From 1a55ec6866c7d0723f6969df90970e9e68c8269f Mon Sep 17 00:00:00 2001 From: Thomas Kohler Date: Thu, 31 Oct 2024 19:00:01 +0100 Subject: [PATCH] build(go, deps): switch to Go 1.21 and update modules --- .circleci/config.yml | 8 +-- .github/workflows/golangci-lint.yml | 19 +++--- .golangci.yml | 40 ++++++------- Makefile | 2 +- api/basic_auth.go | 1 + drivers/aio/temperature_sensor_driver.go | 2 +- drivers/ble/microbit/io_pin_driver.go | 12 +++- drivers/ble/parrot/minidrone_driver.go | 6 ++ drivers/ble/sphero/sphero_ollie_driver.go | 7 ++- drivers/common/mfrc522/mfrc522_pcd.go | 4 +- drivers/common/mfrc522/mfrc522_pcd_test.go | 2 +- drivers/common/mfrc522/mfrc522_picc.go | 2 +- drivers/common/spherocommon/spherocommon.go | 2 +- drivers/gpio/hcsr04_driver_test.go | 3 +- drivers/gpio/stepper_driver.go | 1 + drivers/i2c/adafruit1109_driver.go | 2 +- drivers/i2c/adafruit2327_driver.go | 2 +- drivers/i2c/adafruit2348_driver.go | 4 +- drivers/i2c/ads1x15_driver.go | 10 ++-- drivers/i2c/adxl345_driver.go | 6 +- drivers/i2c/bmp180_driver.go | 8 +-- drivers/i2c/drv2605l_driver.go | 1 + drivers/i2c/helpers_test.go | 4 +- drivers/i2c/hmc5883l_driver.go | 13 +++-- drivers/i2c/i2c_connection.go | 6 +- drivers/i2c/i2c_driver.go | 4 +- drivers/i2c/ina3221_driver.go | 4 +- drivers/i2c/jhd1313m1_driver.go | 2 +- drivers/i2c/mcp23017_driver.go | 10 ++-- drivers/i2c/mcp23017_driver_test.go | 2 +- drivers/i2c/pca9501_driver.go | 6 +- drivers/i2c/pca9685_driver.go | 2 +- drivers/i2c/pcf8583_driver.go | 21 ++++--- drivers/i2c/pcf8591_driver.go | 4 +- drivers/i2c/ssd1306_driver.go | 2 +- drivers/i2c/tsl2561_driver.go | 4 +- drivers/serial/sphero/sphero_driver.go | 4 +- drivers/spi/ssd1306_driver.go | 5 +- examples/beaglebone_servo.go | 1 + examples/bleclient_bb8.go | 1 + examples/bleclient_ollie.go | 1 + examples/bleclient_ollie_boost.go | 4 +- examples/bleclient_ollie_multiple.go | 1 + examples/bleclient_ollie_roll.go | 1 + examples/bleclient_sprkplus.go | 1 + examples/digispark_servo.go | 1 + examples/edison_rgb_led.go | 42 -------------- examples/firmata_gpio_max7219.go | 8 +-- examples/firmata_pca9685.go | 1 + examples/firmata_rgb_led.go | 1 + examples/firmata_servo.go | 1 + examples/gopigo3_servo.go | 1 + examples/jetson-nano_servo.go | 1 + examples/joule_rgb_led.go | 42 -------------- examples/raspi_adafruit2327_servo.go | 1 + examples/raspi_stepper_move.go | 1 + examples/serialport_sphero.go | 1 + examples/serialport_sphero_conways.go | 1 + examples/serialport_sphero_master.go | 1 + examples/serialport_sphero_multiple.go | 1 + go.mod | 30 +++++----- go.sum | 58 ++++++++++--------- platforms/adaptors/pwmpinsadaptor.go | 10 ++-- platforms/adaptors/pwmpinsadaptor_test.go | 3 +- platforms/dexter/gopigo3/driver.go | 6 +- platforms/digispark/README.md | 2 + platforms/digispark/digispark_adaptor.go | 6 ++ platforms/digispark/digispark_adaptor_test.go | 3 + platforms/digispark/digispark_i2c.go | 7 ++- platforms/digispark/digispark_i2c_test.go | 3 + platforms/digispark/doc.go | 3 + platforms/dji/tello/driver.go | 9 ++- platforms/firmata/client/client.go | 13 +++-- platforms/firmata/firmata_adaptor.go | 6 +- platforms/firmata/firmata_i2c.go | 4 +- platforms/firmata/firmata_i2c_test.go | 2 +- platforms/intel-iot/curie/imu_driver.go | 30 +++++----- platforms/joystick/bin/scanner.go | 1 + platforms/joystick/joystick_driver.go | 3 + platforms/leap/leap_motion_adaptor_test.go | 2 +- platforms/mavlink/common/mavlink.go | 4 +- platforms/mavlink/mavlink_adaptor_test.go | 2 +- platforms/mavlink/mavlink_driver_test.go | 2 +- platforms/opencv/README.md | 2 + platforms/opencv/camera_driver.go | 7 ++- platforms/opencv/camera_driver_test.go | 3 + platforms/opencv/helpers_test.go | 3 + platforms/opencv/utils.go | 3 + platforms/opencv/utils_test.go | 3 + platforms/opencv/window_driver.go | 7 ++- platforms/opencv/window_driver_test.go | 3 + platforms/parrot/bebop/client/client.go | 9 +++ .../bebop/client/networkframegenerator.go | 7 +-- platforms/particle/adaptor_test.go | 2 + system/digitalpin_gpiod.go | 4 +- system/digitalpin_poll_test.go | 4 +- system/fs_mock_test.go | 4 +- system/i2c_device.go | 1 + system/i2c_device_test.go | 1 + system/pwmpin_sysfs.go | 4 +- utils.go | 30 +++++----- 101 files changed, 344 insertions(+), 313 deletions(-) delete mode 100644 examples/edison_rgb_led.go delete mode 100644 examples/joule_rgb_led.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 168a145fb..476d28d00 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ version: 2 jobs: "test_core_and_drivers_with_coverage": docker: - - image: cimg/go:1.20 + - image: cimg/go:1.21 steps: - checkout - run: @@ -31,7 +31,7 @@ jobs: "test_platforms": docker: - - image: cimg/go:1.20 + - image: cimg/go:1.21 steps: - checkout - run: @@ -45,7 +45,7 @@ jobs: "check_examples": docker: - - image: cimg/go:1.20 + - image: cimg/go:1.21 steps: - checkout - run: @@ -61,7 +61,7 @@ jobs: "fmt_check_examples": docker: - - image: golangci/golangci-lint:v1.56.1 + - image: golangci/golangci-lint:v1.61.0 steps: - checkout - run: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e1489e644..b2c26a30b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -15,16 +15,16 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: '1.21' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.56.1 + version: v1.61.0 # Optional: working directory, useful for monorepos # working-directory: v2 @@ -32,7 +32,8 @@ jobs: # Optional: golangci-lint command line arguments. # mostly there is no problem locally, but on server: "could not import C (cgo preprocessing failed) (typecheck)" # and the digispark adaptor can not be build since switch to linter version 1.54.2 - args: --skip-files="platforms/digispark/littleWire.go,platforms/digispark/digispark_adaptor.go" + args: --exclude-files="platforms/digispark/digispark_adaptor.go" + #args: --exclude-files="platforms/digispark/littleWire.go,platforms/digispark/digispark_adaptor.go" # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true @@ -40,9 +41,3 @@ jobs: # Optional: if set to true then the all caching functionality will be complete disabled, # takes precedence over all other caching options. # skip-cache: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true diff --git a/.golangci.yml b/.golangci.yml index f826bb4c0..5a8954625 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,41 +22,38 @@ run: # By default, it isn't set. modules-download-mode: readonly +issues: # Enables skipping of directories: # - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ # Default: true - skip-dirs-use-default: false + exclude-dirs-use-default: false - # note: examples will be currently omitted by the build tag - skip-dirs: - - platforms/opencv + # note: folders/files can not be excluded from "typecheck" anymore since v1.61.0 linters: # currently active linters: # - # INFO [lintersdb] Active 64 linters: [asasalint asciicheck bidichk bodyclose containedctx contextcheck decorder depguard dogsled dupword durationcheck - # errcheck errchkjson errorlint exportloopref forcetypeassert gci gocheckcompilerdirectives gochecknoinits gochecksumtype gocritic gofmt gofumpt goimports - # gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper inamedparam ineffassign lll makezero mirror misspell musttag nakedret nilerr nilnil - # noctx nolintlint nonamedreturns nosprintfhostport perfsprint prealloc predeclared protogetter reassign revive sloglint staticcheck tagalign tenv - # testableexamples testifylint thelper tparallel unconvert unparam unused usestdlibvars wastedassign] + # INFO [lintersdb] Active 67 linters: [asasalint asciicheck bidichk bodyclose canonicalheader containedctx + # contextcheck decorder depguard dogsled dupword durationcheck errcheck errchkjson errorlint fatcontext + # forcetypeassert gci gocheckcompilerdirectives gochecknoinits gochecksumtype gocritic gofmt gofumpt goimports + # gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper inamedparam ineffassign lll makezero + # mirror misspell mnd musttag nakedret nilerr nilnil noctx nolintlint nonamedreturns nosprintfhostport perfsprint + # prealloc predeclared protogetter reassign revive sloglint spancheck staticcheck tagalign tenv testableexamples + # testifylint thelper tparallel unconvert unparam unused usestdlibvars wastedassign] enable-all: true # https://golangci-lint.run/usage/linters/#enabled-by-default # note: typecheck can not be disabled, it is used to check code compilation disable: - # deprecated - - deadcode # deprecated - - exhaustivestruct # deprecated - - golint # deprecated - - ifshort # deprecated - - interfacer # deprecated - - maligned # deprecated - - nosnakecase # deprecated - - scopelint # deprecated - - structcheck # deprecated - - varcheck # deprecated + # deprecated: none + - gomnd # The linter has been renamed. Replaced by mnd. + # not used for this go version + - copyloopvar # the Go version (1.21) of your project is lower than Go 1.22 + - intrange # the Go version (1.21) of your project is lower than Go 1.22 + - exportloopref # Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar # not used for any reason + - err113 # not used (we allow error creation at return statement) - execinquery # not needed (no sql) - exhaustive # not used (we allow incomplete usage of enum switch, e.g. with default case) - forbidigo # not used (we allow print statements) @@ -64,7 +61,6 @@ linters: - gochecknoglobals # not used (we allow definition of unexposed variables at top level) - godot # not used (seems to be counting peas) - godox # not used (we have many TODOs, so not useful) - - goerr113 # not used (we allow error creation at return statement) - gosmopolitan # not needed (report i18n/l10n anti-patterns) - importas # not needed (there is no alias rule at the moment) - ireturn # not used (we allow return interfaces) @@ -86,9 +82,9 @@ linters: - goconst # useful (reduce bugs) - gocyclo # useful with some tweeks (better understandable code) - goheader # useful, if we introduce a common header (e.g. for copyright) - - gomnd # useful with some exclusions for existing code (e.g. mavlink.go) - interfacebloat # useful with some exclusions at usage of external packages - maintidx # useful with some tweeks (better understandable code), maybe use instead "gocyclo", "gocognit" , "cyclop" + - mnd # useful with some exclusions for existing code (e.g. mavlink.go) - nestif # useful (reduce bugs, simplify code, better understandable code) - nlreturn # more common style, but could become annoying - stylecheck # useful with some tweaking (e.g. underscores in names should be allowed - we use it for constants retrieved from C/C++) diff --git a/Makefile b/Makefile index 46f532518..3245a98ab 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ including_except := $(shell go list ./... | grep -v platforms/opencv) # Run tests on nearly all directories without test cache, with race detection test_race: - go test -failfast -count=1 -race $(including_except) + go test -failfast -count=1 -race $(including_except) -tags libusb # Run tests on nearly all directories without test cache test: diff --git a/api/basic_auth.go b/api/basic_auth.go index 260d2c357..0548dda39 100644 --- a/api/basic_auth.go +++ b/api/basic_auth.go @@ -22,6 +22,7 @@ func BasicAuth(username, password string) http.HandlerFunc { } func secureCompare(given string, actual string) bool { + //nolint:gosec // TODO: fix later if subtle.ConstantTimeEq(int32(len(given)), int32(len(actual))) == 1 { return subtle.ConstantTimeCompare([]byte(given), []byte(actual)) == 1 } diff --git a/drivers/aio/temperature_sensor_driver.go b/drivers/aio/temperature_sensor_driver.go index f415caa1d..fb2c78e83 100644 --- a/drivers/aio/temperature_sensor_driver.go +++ b/drivers/aio/temperature_sensor_driver.go @@ -86,7 +86,7 @@ func TemperatureSensorNtcScaler( if input < 0 { input = 0 } - rTherm := temperaturSensorGetResistance(uint(input), vRef, rOhm, reverse) + rTherm := temperaturSensorGetResistance(uint(input), vRef, rOhm, reverse) //nolint:gosec // checked before temp := ntc.getTemp(rTherm) return temp }) diff --git a/drivers/ble/microbit/io_pin_driver.go b/drivers/ble/microbit/io_pin_driver.go index d45b2d6c2..bcf76bd76 100644 --- a/drivers/ble/microbit/io_pin_driver.go +++ b/drivers/ble/microbit/io_pin_driver.go @@ -72,7 +72,7 @@ func (d *IOPinDriver) ReadPinADConfig() (int, error) { } var result byte for i := 0; i < 4; i++ { - result |= c[i] << uint(i) + result |= c[i] << uint(i) //nolint:gosec // ok here } d.adMask = int(result) @@ -83,6 +83,7 @@ func (d *IOPinDriver) ReadPinADConfig() (int, error) { func (d *IOPinDriver) WritePinADConfig(config int) error { d.adMask = config data := &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(data, binary.LittleEndian, uint32(config)); err != nil { return err } @@ -99,7 +100,7 @@ func (d *IOPinDriver) ReadPinIOConfig() (int, error) { var result byte for i := 0; i < 4; i++ { - result |= c[i] << uint(i) + result |= c[i] << uint(i) //nolint:gosec // ok here } d.ioMask = int(result) @@ -110,6 +111,7 @@ func (d *IOPinDriver) ReadPinIOConfig() (int, error) { func (d *IOPinDriver) WritePinIOConfig(config int) error { d.ioMask = config data := &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(data, binary.LittleEndian, uint32(config)); err != nil { return err } @@ -179,6 +181,7 @@ func (d *IOPinDriver) AnalogRead(pin string) (int, error) { } func (d *IOPinDriver) ensureDigital(pin int) error { + //nolint:gosec // TODO: fix later if bit.IsSet(d.adMask, uint8(pin)) { return d.WritePinADConfig(bit.Clear(d.adMask, uint8(pin))) } @@ -187,6 +190,7 @@ func (d *IOPinDriver) ensureDigital(pin int) error { } func (d *IOPinDriver) ensureAnalog(pin int) error { + //nolint:gosec // TODO: fix later if !bit.IsSet(d.adMask, uint8(pin)) { return d.WritePinADConfig(bit.Set(d.adMask, uint8(pin))) } @@ -195,6 +199,7 @@ func (d *IOPinDriver) ensureAnalog(pin int) error { } func (d *IOPinDriver) ensureInput(pin int) error { + //nolint:gosec // TODO: fix later if !bit.IsSet(d.ioMask, uint8(pin)) { return d.WritePinIOConfig(bit.Set(d.ioMask, uint8(pin))) } @@ -203,8 +208,9 @@ func (d *IOPinDriver) ensureInput(pin int) error { } func (d *IOPinDriver) ensureOutput(pin int) error { + //nolint:gosec // TODO: fix later if bit.IsSet(d.ioMask, uint8(pin)) { - return d.WritePinIOConfig(bit.Clear(d.ioMask, uint8(pin))) + return d.WritePinIOConfig(bit.Clear(d.ioMask, uint8(pin))) //nolint:gosec // TODO: fix later } return nil diff --git a/drivers/ble/parrot/minidrone_driver.go b/drivers/ble/parrot/minidrone_driver.go index e42f1f370..4dee03ef5 100644 --- a/drivers/ble/parrot/minidrone_driver.go +++ b/drivers/ble/parrot/minidrone_driver.go @@ -394,6 +394,7 @@ func (d *MinidroneDriver) generatePcmd() *bytes.Buffer { if err := binary.Write(cmd, binary.LittleEndian, int8(2)); err != nil { panic(err) } + //nolint:gosec // TODO: fix later if err := binary.Write(cmd, binary.LittleEndian, int8(d.stepsfa0a)); err != nil { panic(err) } @@ -409,18 +410,23 @@ func (d *MinidroneDriver) generatePcmd() *bytes.Buffer { if err := binary.Write(cmd, binary.LittleEndian, int8(0)); err != nil { panic(err) } + //nolint:gosec // TODO: fix later if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Flag)); err != nil { panic(err) } + //nolint:gosec // TODO: fix later if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Roll)); err != nil { panic(err) } + //nolint:gosec // TODO: fix later if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Pitch)); err != nil { panic(err) } + //nolint:gosec // TODO: fix later if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Yaw)); err != nil { panic(err) } + //nolint:gosec // TODO: fix later if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Gaz)); err != nil { panic(err) } diff --git a/drivers/ble/sphero/sphero_ollie_driver.go b/drivers/ble/sphero/sphero_ollie_driver.go index cd521e597..a2dfcb54d 100644 --- a/drivers/ble/sphero/sphero_ollie_driver.go +++ b/drivers/ble/sphero/sphero_ollie_driver.go @@ -143,6 +143,7 @@ func (d *OllieDriver) SetRGB(r uint8, g uint8, b uint8) { // Roll tells the Ollie to roll func (d *OllieDriver) Roll(speed uint8, heading uint16) { + //nolint:gosec // TODO: fix later d.sendCraftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30) } @@ -353,13 +354,13 @@ func (d *OllieDriver) handleLocatorDetected(data []uint8) { var x, y int16 if ux > 32255 { - x = int16(ux - 65535) + x = int16(ux - 65535) //nolint:gosec // ok here } else { x = int16(ux) } if uy > 32255 { - y = int16(uy - 65535) + y = int16(uy - 65535) //nolint:gosec // ok here } else { y = int16(uy) } @@ -424,7 +425,7 @@ func (d *OllieDriver) sendCraftPacket(body []uint8, did byte, cid byte) { func (d *OllieDriver) craftPacket(body []uint8, did byte, cid byte) *packet { dlen := len(body) + 1 - hdr := []uint8{0xFF, 0xFF, did, cid, d.seq, uint8(dlen)} + hdr := []uint8{0xFF, 0xFF, did, cid, d.seq, uint8(dlen)} //nolint:gosec // TODO: fix later buf := append(hdr, body...) packet := &packet{ diff --git a/drivers/common/mfrc522/mfrc522_pcd.go b/drivers/common/mfrc522/mfrc522_pcd.go index a6cad3495..a24e53cb0 100644 --- a/drivers/common/mfrc522/mfrc522_pcd.go +++ b/drivers/common/mfrc522/mfrc522_pcd.go @@ -172,6 +172,7 @@ func (d *MFRC522Common) communicateWithPICC(command uint8, sendData []byte, back } // TODO: this is not used at the moment (propagation of IRQ pin) + //nolint:gosec // TODO: fix later if err := d.writeByteData(regComIEn, uint8(irqEn|comIEnRegIRqInv)); err != nil { return err } @@ -337,10 +338,11 @@ func (d *MFRC522Common) readFifo(backData []byte) (uint8, error) { if err != nil { return 0, err } + //nolint:gosec // TODO: fix later if n > uint8(len(backData)) { return 0, fmt.Errorf("more data in FIFO (%d) than expected (%d)", n, len(backData)) } - + //nolint:gosec // TODO: fix later if n < uint8(len(backData)) { return 0, fmt.Errorf("less data in FIFO (%d) than expected (%d)", n, len(backData)) } diff --git a/drivers/common/mfrc522/mfrc522_pcd_test.go b/drivers/common/mfrc522/mfrc522_pcd_test.go index 19c14bf16..3edc0fff4 100644 --- a/drivers/common/mfrc522/mfrc522_pcd_test.go +++ b/drivers/common/mfrc522/mfrc522_pcd_test.go @@ -20,7 +20,7 @@ func (c *busConnMock) ReadByteData(reg uint8) (uint8, error) { switch reg { case regFIFOLevel: - return uint8(len(c.simFifo)), nil + return uint8(len(c.simFifo)), nil //nolint:gosec // ok for test case regFIFOData: c.fifoIdx++ return c.simFifo[c.fifoIdx-1], nil diff --git a/drivers/common/mfrc522/mfrc522_picc.go b/drivers/common/mfrc522/mfrc522_picc.go index 1776daa25..dd228021a 100644 --- a/drivers/common/mfrc522/mfrc522_picc.go +++ b/drivers/common/mfrc522/mfrc522_picc.go @@ -336,7 +336,7 @@ func (d *MFRC522Common) piccActivate() ([]byte, error) { bcc = bcc ^ v } if bcc != backData[4] { - return nil, fmt.Errorf(fmt.Sprintf("BCC mismatch, expected %02x actual %02x", bcc, backData[4])) + return nil, fmt.Errorf("BCC mismatch, expected %02x actual %02x", bcc, backData[4]) } if backData[0] == piccCascadeTag { diff --git a/drivers/common/spherocommon/spherocommon.go b/drivers/common/spherocommon/spherocommon.go index 978ac7dcd..843166825 100644 --- a/drivers/common/spherocommon/spherocommon.go +++ b/drivers/common/spherocommon/spherocommon.go @@ -29,5 +29,5 @@ func CalculateChecksum(buf []byte) byte { for i := range buf { calculatedChecksum += uint16(buf[i]) } - return uint8(^(calculatedChecksum % 256)) + return uint8(^(calculatedChecksum % 256)) //nolint:gosec // TODO: fix later } diff --git a/drivers/gpio/hcsr04_driver_test.go b/drivers/gpio/hcsr04_driver_test.go index 4c32cae5e..554bae5c2 100644 --- a/drivers/gpio/hcsr04_driver_test.go +++ b/drivers/gpio/hcsr04_driver_test.go @@ -1,6 +1,7 @@ package gpio import ( + "errors" "fmt" "strings" "sync" @@ -132,7 +133,7 @@ func TestHCSR04MeasureDistance(t *testing.T) { oldVal = val var err error if tc.simulateWriteErr != "" { - err = fmt.Errorf(tc.simulateWriteErr) + err = errors.New(tc.simulateWriteErr) } return err } diff --git a/drivers/gpio/stepper_driver.go b/drivers/gpio/stepper_driver.go index b33b845fd..5f6d4cd47 100644 --- a/drivers/gpio/stepper_driver.go +++ b/drivers/gpio/stepper_driver.go @@ -308,6 +308,7 @@ func (d *StepperDriver) stepAsynch(stepsToMove float64) error { // t [min] = steps [st] / (steps_per_revolution [st/u] * speed [u/min]) or // t [min] = steps [st] * delay_per_step [min/st], use safety factor 2 and a small offset of 100 ms // prepare this timeout outside of stop function to prevent data race with stepsLeft + //nolint:gosec // TODO: fix later stopTimeout := time.Duration(2*stepsLeft)*d.getDelayPerStep() + 100*time.Millisecond endlessMovement := false diff --git a/drivers/i2c/adafruit1109_driver.go b/drivers/i2c/adafruit1109_driver.go index 92781fea4..2c3433404 100644 --- a/drivers/i2c/adafruit1109_driver.go +++ b/drivers/i2c/adafruit1109_driver.go @@ -281,7 +281,7 @@ func adafruit1109ParseID(id string) adafruit1109PortPin { items := strings.Split(id, "_") io := uint8(0) if io64, err := strconv.ParseUint(items[1], 10, 32); err == nil { - io = uint8(io64) + io = uint8(io64) //nolint:gosec // TODO: fix later } return adafruit1109PortPin{port: items[0], pin: io} } diff --git a/drivers/i2c/adafruit2327_driver.go b/drivers/i2c/adafruit2327_driver.go index c26ff5d87..6b42b8c78 100644 --- a/drivers/i2c/adafruit2327_driver.go +++ b/drivers/i2c/adafruit2327_driver.go @@ -41,5 +41,5 @@ func (a *Adafruit2327Driver) SetServoMotorFreq(freq float64) error { // SetServoMotorPulse is a convenience function to specify the 'tick' value, // between 0-4095, when the signal will turn on, and when it will turn off. func (a *Adafruit2327Driver) SetServoMotorPulse(channel byte, on, off int32) error { - return a.SetPWM(int(channel), uint16(on), uint16(off)) + return a.SetPWM(int(channel), uint16(on), uint16(off)) //nolint:gosec // TODO: fix later } diff --git a/drivers/i2c/adafruit2348_driver.go b/drivers/i2c/adafruit2348_driver.go index 2fdf86a47..f18c2ee3f 100644 --- a/drivers/i2c/adafruit2348_driver.go +++ b/drivers/i2c/adafruit2348_driver.go @@ -125,7 +125,7 @@ func NewAdafruit2348Driver(c Connector, options ...func(Config)) *Adafruit2348Dr // SetDCMotorSpeed will set the appropriate pins to run the specified DC motor for the given speed. func (a *Adafruit2348Driver) SetDCMotorSpeed(dcMotor int, speed int32) error { - return a.SetPWM(int(a.dcMotors[dcMotor].pwmPin), 0, uint16(speed*16)) + return a.SetPWM(int(a.dcMotors[dcMotor].pwmPin), 0, uint16(speed*16)) //nolint:gosec // TODO: fix later } // RunDCMotor will set the appropriate pins to run the specified DC motor for the given direction. @@ -281,9 +281,11 @@ func (a *Adafruit2348Driver) oneStep(motor int, dir Adafruit2348Direction, style a.stepperMotors[motor].currentStep %= adafruit2348StepperMicrosteps * 4 // only really used for microstepping, otherwise always on! + //nolint:gosec // TODO: fix later if err := a.SetPWM(int(a.stepperMotors[motor].pwmPinA), 0, uint16(pwmA*16)); err != nil { return 0, err } + //nolint:gosec // TODO: fix later if err := a.SetPWM(int(a.stepperMotors[motor].pwmPinB), 0, uint16(pwmB*16)); err != nil { return 0, err } diff --git a/drivers/i2c/ads1x15_driver.go b/drivers/i2c/ads1x15_driver.go index 1e3fbb30a..6f8690e3d 100644 --- a/drivers/i2c/ads1x15_driver.go +++ b/drivers/i2c/ads1x15_driver.go @@ -394,10 +394,10 @@ func (d *ADS1x15Driver) rawRead(channel int, channelOffset int, gain int, dataRa // Specify mux value. mux := channel + channelOffset - config |= uint16((mux & 0x07) << ads1x15ConfigMuxOffset) + config |= uint16((mux & 0x07) << ads1x15ConfigMuxOffset) //nolint:gosec // TODO: fix later // Set the programmable gain amplifier bits. - config |= uint16(gain) << ads1x15ConfigPgaOffset + config |= uint16(gain) << ads1x15ConfigPgaOffset //nolint:gosec // TODO: fix later // Set the mode (continuous or single shot). config |= ads1x15ConfigModeSingle @@ -525,12 +525,12 @@ func ads1x15GetDataRateBits(dataRates map[int]uint16, dataRate int) (uint16, err // ads1x15BestGainForVoltage returns the gain the most adapted to read up to the specified difference of potential. func ads1x15BestGainForVoltage(voltage float64) (int, error) { - var max float64 + var maximum float64 difference := math.MaxFloat64 currentBestGain := -1 for key, fsr := range ads1x15FullScaleRange { - max = math.Max(max, fsr) + maximum = math.Max(maximum, fsr) newDiff := fsr - voltage if newDiff >= 0 && newDiff < difference { difference = newDiff @@ -539,7 +539,7 @@ func ads1x15BestGainForVoltage(voltage float64) (int, error) { } if currentBestGain < 0 { - return 0, fmt.Errorf("The maximum voltage which can be read is %f", max) + return 0, fmt.Errorf("The maximum voltage which can be read is %f", maximum) } return currentBestGain, nil diff --git a/drivers/i2c/adxl345_driver.go b/drivers/i2c/adxl345_driver.go index 42d577d36..04c205f13 100644 --- a/drivers/i2c/adxl345_driver.go +++ b/drivers/i2c/adxl345_driver.go @@ -239,9 +239,9 @@ func (d *ADXL345Driver) readRawData() (int16, int16, int16, error) { return 0, 0, 0, err } - rx := int16(binary.LittleEndian.Uint16(buf[0:2])) - ry := int16(binary.LittleEndian.Uint16(buf[2:4])) - rz := int16(binary.LittleEndian.Uint16(buf[4:6])) + rx := int16(binary.LittleEndian.Uint16(buf[0:2])) //nolint:gosec // TODO: fix later + ry := int16(binary.LittleEndian.Uint16(buf[2:4])) //nolint:gosec // TODO: fix later + rz := int16(binary.LittleEndian.Uint16(buf[4:6])) //nolint:gosec // TODO: fix later return rx, ry, rz, nil } diff --git a/drivers/i2c/bmp180_driver.go b/drivers/i2c/bmp180_driver.go index 176945605..62abcfe9d 100644 --- a/drivers/i2c/bmp180_driver.go +++ b/drivers/i2c/bmp180_driver.go @@ -219,13 +219,13 @@ func (d *BMP180Driver) calculatePressure( x1 = (int32(d.calCoeffs.ac3) * b6) >> 13 x2 = (int32(d.calCoeffs.b1) * ((b6 * b6) >> 12)) >> 16 x3 = ((x1 + x2) + 2) >> 2 - b4 := (uint32(d.calCoeffs.ac4) * uint32(x3+32768)) >> 15 - b7 := (uint32(rawPressure-b3) * (50000 >> uint(oversampling))) + b4 := (uint32(d.calCoeffs.ac4) * uint32(x3+32768)) >> 15 //nolint:gosec // TODO: fix later + b7 := (uint32(rawPressure-b3) * (50000 >> uint(oversampling))) //nolint:gosec // TODO: fix later var p int32 if b7 < 0x80000000 { - p = int32((b7 << 1) / b4) + p = int32((b7 << 1) / b4) //nolint:gosec // TODO: fix later } else { - p = int32((b7 / b4) << 1) + p = int32((b7 / b4) << 1) //nolint:gosec // TODO: fix later } x1 = (p >> 8) * (p >> 8) x1 = (x1 * 3038) >> 16 diff --git a/drivers/i2c/drv2605l_driver.go b/drivers/i2c/drv2605l_driver.go index a29995bc6..b845cb032 100644 --- a/drivers/i2c/drv2605l_driver.go +++ b/drivers/i2c/drv2605l_driver.go @@ -163,6 +163,7 @@ func (d *DRV2605LDriver) SetSequence(waveforms []uint8) error { waveforms = waveforms[0:8] } for i, w := range waveforms { + //nolint:gosec // TODO: fix later if err := d.connection.WriteByteData(uint8(drv2605RegWaveSeq1+i), w); err != nil { return err } diff --git a/drivers/i2c/helpers_test.go b/drivers/i2c/helpers_test.go index 0a043d744..87bc55e1b 100644 --- a/drivers/i2c/helpers_test.go +++ b/drivers/i2c/helpers_test.go @@ -127,8 +127,8 @@ func (t *i2cTestAdaptor) WriteByteData(reg uint8, val uint8) error { func (t *i2cTestAdaptor) WriteWordData(reg uint8, val uint16) error { t.mtx.Lock() defer t.mtx.Unlock() - low := uint8(val & 0xff) - high := uint8((val >> 8) & 0xff) + low := uint8(val & 0xff) //nolint:gosec // ok here + high := uint8((val >> 8) & 0xff) //nolint:gosec // ok here bytes := []byte{reg, low, high} return t.writeBytes(bytes) diff --git a/drivers/i2c/hmc5883l_driver.go b/drivers/i2c/hmc5883l_driver.go index c43f212ca..83bc5db29 100644 --- a/drivers/i2c/hmc5883l_driver.go +++ b/drivers/i2c/hmc5883l_driver.go @@ -147,7 +147,7 @@ func WithHMC5883LSamplesAveraged(val int) func(Config) { if err := hmc5883lValidateSamplesAveraged(val); err != nil { panic(err) } - d.samplesAvg = uint8(val) + d.samplesAvg = uint8(val) //nolint:gosec // TODO: fix later } else if hmc5883lDebug { log.Printf("Trying to set samples averaged for non-HMC5883LDriver %v", c) } @@ -163,7 +163,7 @@ func WithHMC5883LDataOutputRate(val int) func(Config) { if err := hmc5883lValidateOutputRate(val); err != nil { panic(err) } - d.outputRate = uint32(val) + d.outputRate = uint32(val) //nolint:gosec // TODO: fix later } else if hmc5883lDebug { log.Printf("Trying to set data output rate for non-HMC5883LDriver %v", c) } @@ -179,7 +179,7 @@ func WithHMC5883LApplyBias(val int) func(Config) { if err := hmc5883lValidateApplyBias(val); err != nil { panic(err) } - d.applyBias = int8(val) + d.applyBias = int8(val) //nolint:gosec // TODO: fix later } else if hmc5883lDebug { log.Printf("Trying to set measurement flow for non-HMC5883LDriver %v", c) } @@ -256,18 +256,21 @@ func (h *HMC5883LDriver) initialize() error { regA := hmc5883lMeasurementFlowBits[h.applyBias] regA |= hmc5883lOutputRateBits[h.outputRate] << 2 regA |= hmc5883lSamplesAvgBits[h.samplesAvg] << 5 + //nolint:gosec // TODO: fix later if err := h.connection.WriteByteData(hmc5883lRegA, uint8(regA)); err != nil { return err } regB := hmc5883lGainBits[h.gain] << 5 + //nolint:gosec // TODO: fix later if err := h.connection.WriteByteData(hmc5883lRegB, uint8(regB)); err != nil { return err } - + //nolint:gosec // TODO: fix later return h.connection.WriteByteData(hmc5883lRegMode, uint8(h.measurementMode)) } func hmc5883lValidateSamplesAveraged(samplesAvg int) error { + //nolint:gosec // TODO: fix later if _, ok := hmc5883lSamplesAvgBits[uint8(samplesAvg)]; ok { return nil } @@ -282,6 +285,7 @@ func hmc5883lValidateSamplesAveraged(samplesAvg int) error { } func hmc5883lValidateOutputRate(outputRate int) error { + //nolint:gosec // TODO: fix later if _, ok := hmc5883lOutputRateBits[uint32(outputRate)]; ok { return nil } @@ -296,6 +300,7 @@ func hmc5883lValidateOutputRate(outputRate int) error { } func hmc5883lValidateApplyBias(applyBias int) error { + //nolint:gosec // TODO: fix later if _, ok := hmc5883lMeasurementFlowBits[int8(applyBias)]; ok { return nil } diff --git a/drivers/i2c/i2c_connection.go b/drivers/i2c/i2c_connection.go index e1c08a36d..0916bc4ca 100644 --- a/drivers/i2c/i2c_connection.go +++ b/drivers/i2c/i2c_connection.go @@ -29,8 +29,8 @@ var ( type bitState uint8 const ( - clear bitState = 0x00 - set bitState = 0x01 + clearBit bitState = 0x00 + setBit bitState = 0x01 ) // Connection is a connection to an I2C device with a specified address @@ -115,7 +115,7 @@ func twosComplement16Bit(uValue uint16) int16 { if result&0x8000 != 0 { result -= 1 << 16 } - return int16(result) + return int16(result) //nolint:gosec // ok here } func swapBytes(value uint16) uint16 { diff --git a/drivers/i2c/i2c_driver.go b/drivers/i2c/i2c_driver.go index 296b1c0c7..23409c0c1 100644 --- a/drivers/i2c/i2c_driver.go +++ b/drivers/i2c/i2c_driver.go @@ -131,13 +131,13 @@ func (d *Driver) Write(pin string, val int) error { if val > 0xFFFF { buf := make([]byte, 4) - binary.LittleEndian.PutUint32(buf, uint32(val)) + binary.LittleEndian.PutUint32(buf, uint32(val)) //nolint:gosec // ok here return d.connection.WriteBlockData(register, buf) } if val > 0xFF { return d.connection.WriteWordData(register, uint16(val)) } - return d.connection.WriteByteData(register, uint8(val)) + return d.connection.WriteByteData(register, uint8(val)) //nolint:gosec // ok here } // Read implements a simple read mechanism from the given register of an i2c device. diff --git a/drivers/i2c/ina3221_driver.go b/drivers/i2c/ina3221_driver.go index 6ff5ab7a2..743314d91 100644 --- a/drivers/i2c/ina3221_driver.go +++ b/drivers/i2c/ina3221_driver.go @@ -124,7 +124,7 @@ func (i *INA3221Driver) getBusVoltageRaw(channel INA3221Channel) (int16, error) value -= 0x10000 } - return int16(value), nil + return int16(value), nil //nolint:gosec // TODO: fix later } // getShuntVoltageRaw gets the raw shunt voltage (16-bit signed integer, so +-32767) @@ -139,7 +139,7 @@ func (i *INA3221Driver) getShuntVoltageRaw(channel INA3221Channel) (int16, error value -= 0x10000 } - return int16(value), nil + return int16(value), nil //nolint:gosec // TODO: fix later } // reads word from supplied register address diff --git a/drivers/i2c/jhd1313m1_driver.go b/drivers/i2c/jhd1313m1_driver.go index 9d17818ec..0a524420a 100644 --- a/drivers/i2c/jhd1313m1_driver.go +++ b/drivers/i2c/jhd1313m1_driver.go @@ -303,7 +303,7 @@ func (d *JHD1313M1Driver) SetCustomChar(pos int, charMap [8]byte) error { if pos > 7 { return fmt.Errorf("can't set a custom character at a position greater than 7") } - location := uint8(pos) + location := uint8(pos) //nolint:gosec // checked before if err := d.command([]byte{LCD_SETCGRAMADDR | (location << 3)}); err != nil { return err } diff --git a/drivers/i2c/mcp23017_driver.go b/drivers/i2c/mcp23017_driver.go index def7fe527..80def1220 100644 --- a/drivers/i2c/mcp23017_driver.go +++ b/drivers/i2c/mcp23017_driver.go @@ -273,7 +273,7 @@ func (m *MCP23017Driver) WriteGPIO(pin uint8, portStr string, val uint8) error { if !m.mcpBehav.autoIODirOff { // Set IODIR register bit for given pin to an output by clearing bit. // can't call SetPinMode() because mutex will cause deadlock - if err := m.write(selectedPort.IODIR, pin, clear); err != nil { + if err := m.write(selectedPort.IODIR, pin, clearBit); err != nil { return err } } @@ -290,7 +290,7 @@ func (m *MCP23017Driver) ReadGPIO(pin uint8, portStr string) (uint8, error) { if !m.mcpBehav.autoIODirOff { // Set IODIR register bit for given pin to an input by set bit. // can't call SetPinMode() because mutex will cause deadlock - if err := m.write(selectedPort.IODIR, pin, set); err != nil { + if err := m.write(selectedPort.IODIR, pin, setBit); err != nil { return 0, err } } @@ -323,10 +323,10 @@ func (m *MCP23017Driver) write(reg uint8, pin uint8, state bitState) error { } var val uint8 - if state == clear { - val = uint8(bit.Clear(int(valOrg), pin)) + if state == clearBit { + val = uint8(bit.Clear(int(valOrg), pin)) //nolint:gosec // TODO: fix later } else { - val = uint8(bit.Set(int(valOrg), pin)) + val = uint8(bit.Set(int(valOrg), pin)) //nolint:gosec // TODO: fix later } if val != valOrg || m.mcpBehav.forceRefresh { diff --git a/drivers/i2c/mcp23017_driver_test.go b/drivers/i2c/mcp23017_driver_test.go index 0228d982b..e5a5ec9c7 100644 --- a/drivers/i2c/mcp23017_driver_test.go +++ b/drivers/i2c/mcp23017_driver_test.go @@ -1,4 +1,4 @@ -//nolint:forcetypeassert // ok here +//nolint:forcetypeassert,gosec // ok here package i2c import ( diff --git a/drivers/i2c/pca9501_driver.go b/drivers/i2c/pca9501_driver.go index a71934ca7..b68730b2e 100644 --- a/drivers/i2c/pca9501_driver.go +++ b/drivers/i2c/pca9501_driver.go @@ -84,7 +84,7 @@ func (p *PCA9501Driver) WriteGPIO(pin uint8, val uint8) error { // set pin as output by clearing bit iodirVal := bit.Clear(int(iodir), pin) // write CTRL register - err = p.connection.WriteByte(uint8(iodirVal)) + err = p.connection.WriteByte(uint8(iodirVal)) //nolint:gosec // TODO: fix later if err != nil { return err } @@ -101,7 +101,7 @@ func (p *PCA9501Driver) WriteGPIO(pin uint8, val uint8) error { nVal = bit.Set(int(cVal), pin) } // write new value to port - err = p.connection.WriteByte(uint8(nVal)) + err = p.connection.WriteByte(uint8(nVal)) //nolint:gosec // TODO: fix later if err != nil { return err } @@ -121,7 +121,7 @@ func (p *PCA9501Driver) ReadGPIO(pin uint8) (uint8, error) { // set pin as input by setting bit iodirVal := bit.Set(int(iodir), pin) // write CTRL register - err = p.connection.WriteByte(uint8(iodirVal)) + err = p.connection.WriteByte(uint8(iodirVal)) //nolint:gosec // TODO: fix later if err != nil { return 0, err } diff --git a/drivers/i2c/pca9685_driver.go b/drivers/i2c/pca9685_driver.go index 24b6a7fdd..bd9e040b4 100644 --- a/drivers/i2c/pca9685_driver.go +++ b/drivers/i2c/pca9685_driver.go @@ -77,7 +77,7 @@ func NewPCA9685Driver(c Connector, options ...func(Config)) *PCA9685Driver { channel, _ := strconv.Atoi(params["channel"].(string)) on, _ := strconv.Atoi(params["on"].(string)) off, _ := strconv.Atoi(params["off"].(string)) - return p.SetPWM(channel, uint16(on), uint16(off)) + return p.SetPWM(channel, uint16(on), uint16(off)) //nolint:gosec // TODO: fix later }) p.AddCommand("SetPWMFreq", func(params map[string]interface{}) interface{} { freq, _ := strconv.ParseFloat(params["freq"].(string), 32) diff --git a/drivers/i2c/pcf8583_driver.go b/drivers/i2c/pcf8583_driver.go index 70883b72a..34d605f5e 100644 --- a/drivers/i2c/pcf8583_driver.go +++ b/drivers/i2c/pcf8583_driver.go @@ -152,14 +152,14 @@ func (d *PCF8583Driver) WriteTime(val time.Time) error { []byte{ ctrlRegVal | uint8(pcf8583CtrlStopCounting), // sub seconds in 1/10th seconds - pcf8583encodeBcd(uint8(val.Nanosecond() / 1000000 / 10)), - pcf8583encodeBcd(uint8(val.Second())), - pcf8583encodeBcd(uint8(val.Minute())), - pcf8583encodeBcd(uint8(val.Hour())), + pcf8583encodeBcd(uint8(val.Nanosecond() / 1000000 / 10)), //nolint:gosec // TODO: fix later + pcf8583encodeBcd(uint8(val.Second())), //nolint:gosec // TODO: fix later + pcf8583encodeBcd(uint8(val.Minute())), //nolint:gosec // TODO: fix later + pcf8583encodeBcd(uint8(val.Hour())), //nolint:gosec // TODO: fix later // year, date (we keep the year counter zero and set the offset) - pcf8583encodeBcd(uint8(day)), + pcf8583encodeBcd(uint8(day)), //nolint:gosec // TODO: fix later // month, weekday (not BCD): Sunday = 0, Monday = 1 ... - uint8(val.Weekday())<<5 | pcf8583encodeBcd(uint8(month)), + uint8(val.Weekday())<<5 | pcf8583encodeBcd(uint8(month)), //nolint:gosec // TODO: fix later }) if err != nil { return err @@ -221,9 +221,12 @@ func (d *PCF8583Driver) WriteCounter(val int32) error { } err = d.connection.WriteBlockData(uint8(pcf8583Reg_CTRL), []byte{ - ctrlRegVal | uint8(pcf8583CtrlStopCounting), // stop - pcf8583encodeBcd(uint8(val % 100)), // 2 lowest digits - pcf8583encodeBcd(uint8((val / 100) % 100)), // 2 middle digits + ctrlRegVal | uint8(pcf8583CtrlStopCounting), // stop + //nolint:gosec // TODO: fix later + pcf8583encodeBcd(uint8(val % 100)), // 2 lowest digits + //nolint:gosec // TODO: fix later + pcf8583encodeBcd(uint8((val / 100) % 100)), // 2 middle digits + //nolint:gosec // TODO: fix later pcf8583encodeBcd(uint8((val / 10000) % 100)), // 2 highest digits }) if err != nil { diff --git a/drivers/i2c/pcf8591_driver.go b/drivers/i2c/pcf8591_driver.go index 8946cc03b..f5d2b9469 100644 --- a/drivers/i2c/pcf8591_driver.go +++ b/drivers/i2c/pcf8591_driver.go @@ -143,8 +143,8 @@ func WithPCF8591With400kbitStabilization(additionalReadWrite, additionalRead int if additionalRead < 0 { additionalRead = 2 // works in most cases } - p.additionalReadWrite = uint8(additionalReadWrite) - p.additionalRead = uint8(additionalRead) + p.additionalReadWrite = uint8(additionalReadWrite) //nolint:gosec // checked before + p.additionalRead = uint8(additionalRead) //nolint:gosec // checked before if pcf8591Debug { log.Printf("400 kbit stabilization for PCF8591Driver set rw: %d, r: %d", p.additionalReadWrite, p.additionalRead) } diff --git a/drivers/i2c/ssd1306_driver.go b/drivers/i2c/ssd1306_driver.go index f7a674d05..4153a0b3c 100644 --- a/drivers/i2c/ssd1306_driver.go +++ b/drivers/i2c/ssd1306_driver.go @@ -163,7 +163,7 @@ func (d *DisplayBuffer) Clear() { // SetPixel sets the x, y pixel with c color. func (d *DisplayBuffer) SetPixel(x, y, c int) { idx := x + (y/d.pageSize)*d.width - bit := uint(y) % uint(d.pageSize) + bit := uint(y) % uint(d.pageSize) //nolint:gosec // TODO: fix later if c == 0 { d.buffer[idx] &= ^(1 << bit) } else { diff --git a/drivers/i2c/tsl2561_driver.go b/drivers/i2c/tsl2561_driver.go index 44e94ac58..a3c5a9b0a 100644 --- a/drivers/i2c/tsl2561_driver.go +++ b/drivers/i2c/tsl2561_driver.go @@ -215,7 +215,7 @@ func (d *TSL2561Driver) SetIntegrationTime(time TSL2561IntegrationTime) error { return err } - timeGainVal := uint8(time) | uint8(d.gain) + timeGainVal := uint8(time) | uint8(d.gain) //nolint:gosec // TODO: fix later if err := d.connection.WriteByteData(tsl2561CommandBit|tsl2561RegisterTiming, timeGainVal); err != nil { return err } @@ -230,7 +230,7 @@ func (d *TSL2561Driver) SetGain(gain TSL2561Gain) error { return err } - timeGainVal := uint8(d.integrationTime) | uint8(gain) + timeGainVal := uint8(d.integrationTime) | uint8(gain) //nolint:gosec // TODO: fix later if err := d.connection.WriteByteData(tsl2561CommandBit|tsl2561RegisterTiming, timeGainVal); err != nil { return err } diff --git a/drivers/serial/sphero/sphero_driver.go b/drivers/serial/sphero/sphero_driver.go index c9a80cbaa..907d171bd 100644 --- a/drivers/serial/sphero/sphero_driver.go +++ b/drivers/serial/sphero/sphero_driver.go @@ -183,6 +183,7 @@ func (d *SpheroDriver) SetRotationRate(level uint8) { // SetHeading sets the heading of the Sphero func (d *SpheroDriver) SetHeading(heading uint16) { + //nolint:gosec // TODO: fix later d.sendCraftPacket([]uint8{uint8(heading >> 8), uint8(heading & 0xFF)}, 0x01) } @@ -197,6 +198,7 @@ func (d *SpheroDriver) SetStabilization(on bool) { // Roll sends a roll command to the Sphero gives a speed and heading func (d *SpheroDriver) Roll(speed uint8, heading uint16) { + //nolint:gosec // TODO: fix later d.sendCraftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x30) } @@ -393,7 +395,7 @@ func (d *SpheroDriver) sendCraftPacket(body []uint8, cid byte) { func (d *SpheroDriver) craftPacket(body []uint8, cid byte) *packet { dlen := len(body) + 1 did := uint8(0x02) - hdr := []uint8{0xFF, 0xFF, did, cid, d.seq, uint8(dlen)} + hdr := []uint8{0xFF, 0xFF, did, cid, d.seq, uint8(dlen)} //nolint:gosec // TODO: fix later buf := append(hdr, body...) packet := &packet{ diff --git a/drivers/spi/ssd1306_driver.go b/drivers/spi/ssd1306_driver.go index 819a6a2a7..e13db111b 100644 --- a/drivers/spi/ssd1306_driver.go +++ b/drivers/spi/ssd1306_driver.go @@ -84,7 +84,7 @@ func (d *DisplayBuffer) Clear() { // SetPixel sets the x, y pixel with c color func (d *DisplayBuffer) SetPixel(x, y, c int) { idx := x + (y/d.pageSize)*d.width - bit := uint(y) % uint(d.pageSize) + bit := uint(y) % uint(d.pageSize) //nolint:gosec // TODO: fix later if c == 0 { d.buffer[idx] &= ^(1 << bit) } else { @@ -305,6 +305,7 @@ func (s *SSD1306Driver) Display() error { if err := s.command(0); err != nil { return err } + //nolint:gosec // TODO: fix later if err := s.command(uint8(s.DisplayWidth) - 1); err != nil { return err } @@ -314,6 +315,7 @@ func (s *SSD1306Driver) Display() error { if err := s.command(0); err != nil { return err } + //nolint:gosec // TODO: fix later if err := s.command(uint8(s.pageSize) - 1); err != nil { return err } @@ -371,6 +373,7 @@ func (s *SSD1306Driver) initialize() error { if err := s.command(ssd1306SetMultiplexRatio); err != nil { return err } + //nolint:gosec // TODO: fix later if err := s.command(uint8(s.DisplayHeight) - 1); err != nil { return err } diff --git a/examples/beaglebone_servo.go b/examples/beaglebone_servo.go index 26fd68a5a..325c01400 100644 --- a/examples/beaglebone_servo.go +++ b/examples/beaglebone_servo.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/bleclient_bb8.go b/examples/bleclient_bb8.go index f22a4db1e..18500cc99 100644 --- a/examples/bleclient_bb8.go +++ b/examples/bleclient_bb8.go @@ -13,6 +13,7 @@ NOTE: sudo is required to use BLE in Linux */ +//nolint:gosec // ok here package main import ( diff --git a/examples/bleclient_ollie.go b/examples/bleclient_ollie.go index 82f91762c..208354df0 100644 --- a/examples/bleclient_ollie.go +++ b/examples/bleclient_ollie.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/bleclient_ollie_boost.go b/examples/bleclient_ollie_boost.go index b4a10bf8c..72e1b4963 100644 --- a/examples/bleclient_ollie_boost.go +++ b/examples/bleclient_ollie_boost.go @@ -20,11 +20,11 @@ func main() { ollieBot := sphero.NewOllieDriver(bleAdaptor) work := func() { - head := 90 + head := uint16(90) ollieBot.SetRGB(255, 0, 0) ollieBot.Boost(true) gobot.Every(1*time.Second, func() { - ollieBot.Roll(0, uint16(head)) + ollieBot.Roll(0, head) time.Sleep(1 * time.Second) head += 90 head = head % 360 diff --git a/examples/bleclient_ollie_multiple.go b/examples/bleclient_ollie_multiple.go index 5195e6f82..0ced0c475 100644 --- a/examples/bleclient_ollie_multiple.go +++ b/examples/bleclient_ollie_multiple.go @@ -12,6 +12,7 @@ NOTE: sudo is required to use BLE in Linux */ +//nolint:gosec // ok here package main import ( diff --git a/examples/bleclient_ollie_roll.go b/examples/bleclient_ollie_roll.go index 7bcba8401..bb7b51259 100644 --- a/examples/bleclient_ollie_roll.go +++ b/examples/bleclient_ollie_roll.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/bleclient_sprkplus.go b/examples/bleclient_sprkplus.go index 36c5d1914..d814c667c 100644 --- a/examples/bleclient_sprkplus.go +++ b/examples/bleclient_sprkplus.go @@ -13,6 +13,7 @@ NOTE: sudo is required to use BLE in Linux */ +//nolint:gosec // ok here package main import ( diff --git a/examples/digispark_servo.go b/examples/digispark_servo.go index 4a6fd4d95..5d0e3630b 100644 --- a/examples/digispark_servo.go +++ b/examples/digispark_servo.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/edison_rgb_led.go b/examples/edison_rgb_led.go deleted file mode 100644 index 966887dc1..000000000 --- a/examples/edison_rgb_led.go +++ /dev/null @@ -1,42 +0,0 @@ -//go:build example -// +build example - -// -// Do not build by default. - -package main - -import ( - "fmt" - "time" - - "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/drivers/gpio" - "gobot.io/x/gobot/v2/platforms/intel-iot/edison" -) - -func main() { - e := edison.NewAdaptor() - led := gpio.NewRgbLedDriver(e, "3", "5", "6") - - work := func() { - gobot.Every(1*time.Second, func() { - r := uint8(gobot.Rand(255)) - g := uint8(gobot.Rand(255)) - b := uint8(gobot.Rand(255)) - if err := led.SetRGB(r, g, b); err != nil { - fmt.Println(err) - } - }) - } - - robot := gobot.NewRobot("rgbBot", - []gobot.Connection{e}, - []gobot.Device{led}, - work, - ) - - if err := robot.Start(); err != nil { - panic(err) - } -} diff --git a/examples/firmata_gpio_max7219.go b/examples/firmata_gpio_max7219.go index 87f3b7682..d0069f971 100644 --- a/examples/firmata_gpio_max7219.go +++ b/examples/firmata_gpio_max7219.go @@ -29,7 +29,7 @@ import ( func main() { firmataAdaptor := firmata.NewAdaptor(os.Args[1]) - max := gpio.NewMAX7219Driver(firmataAdaptor, "11", "10", "9", 4) + maxim := gpio.NewMAX7219Driver(firmataAdaptor, "11", "10", "9", 4) var digit byte = 1 // digit address goes from 0x01 (MAX7219Digit0) to 0x08 (MAX7219Digit8) var bits byte = 1 @@ -38,10 +38,10 @@ func main() { work := func() { gobot.Every(100*time.Millisecond, func() { - if err := max.ClearAll(); err != nil { + if err := maxim.ClearAll(); err != nil { fmt.Println(err) } - if err := max.One(module, digit, bits); err != nil { + if err := maxim.One(module, digit, bits); err != nil { fmt.Println(err) } bits = bits << 1 @@ -65,7 +65,7 @@ func main() { robot := gobot.NewRobot("Max7219Bot", []gobot.Connection{firmataAdaptor}, - []gobot.Device{max}, + []gobot.Device{maxim}, work, ) diff --git a/examples/firmata_pca9685.go b/examples/firmata_pca9685.go index 05e56c766..58a9f6302 100644 --- a/examples/firmata_pca9685.go +++ b/examples/firmata_pca9685.go @@ -11,6 +11,7 @@ go run examples/firmata_pca9685.go /dev/ttyACM0 */ +//nolint:gosec // ok here package main import ( diff --git a/examples/firmata_rgb_led.go b/examples/firmata_rgb_led.go index 8a246b66d..0f403f1d4 100644 --- a/examples/firmata_rgb_led.go +++ b/examples/firmata_rgb_led.go @@ -11,6 +11,7 @@ go run examples/firmata_rgb_led.go /dev/ttyACM0 */ +//nolint:gosec // ok here package main import ( diff --git a/examples/firmata_servo.go b/examples/firmata_servo.go index ed1cbb07d..0663614b3 100644 --- a/examples/firmata_servo.go +++ b/examples/firmata_servo.go @@ -11,6 +11,7 @@ go run examples/firmata_servo.go /dev/ttyACM0 */ +//nolint:gosec // ok here package main import ( diff --git a/examples/gopigo3_servo.go b/examples/gopigo3_servo.go index 04e50bfdf..c1aa98ffc 100644 --- a/examples/gopigo3_servo.go +++ b/examples/gopigo3_servo.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/jetson-nano_servo.go b/examples/jetson-nano_servo.go index 5eaafe92b..ee62319d9 100644 --- a/examples/jetson-nano_servo.go +++ b/examples/jetson-nano_servo.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main // diff --git a/examples/joule_rgb_led.go b/examples/joule_rgb_led.go deleted file mode 100644 index 6f008969a..000000000 --- a/examples/joule_rgb_led.go +++ /dev/null @@ -1,42 +0,0 @@ -//go:build example -// +build example - -// -// Do not build by default. - -package main - -import ( - "fmt" - "time" - - "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/drivers/gpio" - "gobot.io/x/gobot/v2/platforms/intel-iot/joule" -) - -func main() { - e := joule.NewAdaptor() - led := gpio.NewRgbLedDriver(e, "25", "27", "29") - - work := func() { - gobot.Every(1*time.Second, func() { - r := uint8(gobot.Rand(255)) - g := uint8(gobot.Rand(255)) - b := uint8(gobot.Rand(255)) - if err := led.SetRGB(r, g, b); err != nil { - fmt.Println(err) - } - }) - } - - robot := gobot.NewRobot("rgbBot", - []gobot.Connection{e}, - []gobot.Device{led}, - work, - ) - - if err := robot.Start(); err != nil { - panic(err) - } -} diff --git a/examples/raspi_adafruit2327_servo.go b/examples/raspi_adafruit2327_servo.go index d87d78103..846137c73 100644 --- a/examples/raspi_adafruit2327_servo.go +++ b/examples/raspi_adafruit2327_servo.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/raspi_stepper_move.go b/examples/raspi_stepper_move.go index d214d5438..f20b2eee8 100644 --- a/examples/raspi_stepper_move.go +++ b/examples/raspi_stepper_move.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/serialport_sphero.go b/examples/serialport_sphero.go index af709cc13..1947542f6 100644 --- a/examples/serialport_sphero.go +++ b/examples/serialport_sphero.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/serialport_sphero_conways.go b/examples/serialport_sphero_conways.go index 73e974791..11de8517f 100644 --- a/examples/serialport_sphero_conways.go +++ b/examples/serialport_sphero_conways.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/serialport_sphero_master.go b/examples/serialport_sphero_master.go index 793858b3d..2679ab17d 100644 --- a/examples/serialport_sphero_master.go +++ b/examples/serialport_sphero_master.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/examples/serialport_sphero_multiple.go b/examples/serialport_sphero_multiple.go index 12058f566..6d8c70374 100644 --- a/examples/serialport_sphero_multiple.go +++ b/examples/serialport_sphero_multiple.go @@ -4,6 +4,7 @@ // // Do not build by default. +//nolint:gosec // ok here package main import ( diff --git a/go.mod b/go.mod index 3bd97c5e0..1e9877423 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,25 @@ module gobot.io/x/gobot/v2 -go 1.20 +go 1.21 require ( github.com/0xcafed00d/joystick v1.0.1 github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0 - github.com/eclipse/paho.mqtt.golang v1.5.0 + github.com/eclipse/paho.mqtt.golang v1.4.3 github.com/gofrs/uuid v4.4.0+incompatible github.com/hashicorp/go-multierror v1.1.1 github.com/hybridgroup/go-ardrone v0.0.0-20140402002621-b9750d8d7b78 github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e - github.com/nats-io/nats.go v1.37.0 + github.com/nats-io/nats.go v1.31.0 github.com/nsf/termbox-go v1.1.1 github.com/sigurn/crc8 v0.0.0-20220107193325-2243fe600f9f - github.com/stretchr/testify v1.9.0 - github.com/warthog618/gpiod v0.8.3 - go.bug.st/serial v1.6.2 - gocv.io/x/gocv v0.39.0 - golang.org/x/net v0.30.0 - golang.org/x/sys v0.26.0 + github.com/stretchr/testify v1.8.4 + github.com/warthog618/gpiod v0.8.2 + go.bug.st/serial v1.6.1 + gocv.io/x/gocv v0.35.0 + golang.org/x/net v0.19.0 + golang.org/x/sys v0.16.0 periph.io/x/conn/v3 v3.7.0 periph.io/x/host/v3 v3.8.2 tinygo.org/x/bluetooth v0.8.0 @@ -31,18 +31,18 @@ require ( github.com/fatih/structs v1.1.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/gorilla/websocket v1.5.3 // indirect + github.com/gorilla/websocket v1.5.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/klauspost/compress v1.17.11 // indirect + github.com/klauspost/compress v1.17.4 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect - github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e // indirect + github.com/muka/go-bluetooth v0.0.0-20221213043340-85dc80edc4e1 // indirect github.com/nats-io/nkeys v0.4.7 // indirect github.com/nats-io/nuid v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/saltosystems/winrt-go v0.0.0-20240110120258-ad49e9790c38 // indirect + github.com/saltosystems/winrt-go v0.0.0-20231011131235-9071442c0c84 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/tinygo-org/cbgo v0.0.4 // indirect - golang.org/x/crypto v0.28.0 // indirect - golang.org/x/sync v0.8.0 // indirect + golang.org/x/crypto v0.17.0 // indirect + golang.org/x/sync v0.6.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c1773eb6b..84697da48 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0 h1:C7t6eeMaEQVy6e8CarIhscYQlNmw5e3G36y7l7Y21Ao= github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0/go.mod h1:56wL82FO0bfMU5RvfXoIwSOP2ggqqxT+tAfNEIyxuHw= -github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o= -github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk= +github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= +github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= @@ -21,8 +21,8 @@ github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= -github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -32,8 +32,8 @@ github.com/hybridgroup/go-ardrone v0.0.0-20140402002621-b9750d8d7b78 h1:7of6LJZ4 github.com/hybridgroup/go-ardrone v0.0.0-20140402002621-b9750d8d7b78/go.mod h1:YllNbhGM1UEcySxCv1BWK5lre7QLmJJ+O0ADUOo2nbc= github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e h1:xCcwD5FOXul+j1dn8xD16nbrhJkkum/Cn+jTd/u1LhY= github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e/go.mod h1:eagM805MRKrioHYuU7iKLUyFPVKqVV6um5DAvCkUtXs= -github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= -github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= +github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -41,10 +41,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e h1:1Sc4DqlgszKejMkjydCSq8zOKmF+hr8odAl5JoBZ+ec= -github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= +github.com/muka/go-bluetooth v0.0.0-20221213043340-85dc80edc4e1 h1:BuVRHr4HHJbk1DHyWkArJ7E8J/VA8ncCr/VLnQFazBo= +github.com/muka/go-bluetooth v0.0.0-20221213043340-85dc80edc4e1/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= +github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E= +github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8= github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= @@ -53,13 +53,14 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY= github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/paypal/gatt v0.0.0-20151011220935-4ae819d591cf/go.mod h1:+AwQL2mK3Pd3S+TUwg0tYQjid0q1txyNUJuuSmz8Kdk= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/saltosystems/winrt-go v0.0.0-20240110120258-ad49e9790c38 h1:YcsdT0vhLMBWScwoO9FHZdjcFqjIWfQENMzq0PNxODs= -github.com/saltosystems/winrt-go v0.0.0-20240110120258-ad49e9790c38/go.mod h1:CIltaIm7qaANUIvzr0Vmz71lmQMAIbGJ7cvgzX7FMfA= +github.com/saltosystems/winrt-go v0.0.0-20231011131235-9071442c0c84 h1:LX7qSkrsG8fKKVubiUnqfGdi/yBBnVTBR13LkqXycog= +github.com/saltosystems/winrt-go v0.0.0-20231011131235-9071442c0c84/go.mod h1:CIltaIm7qaANUIvzr0Vmz71lmQMAIbGJ7cvgzX7FMfA= github.com/sigurn/crc8 v0.0.0-20220107193325-2243fe600f9f h1:1R9KdKjCNSd7F8iGTxIpoID9prlYH8nuNYKt0XvweHA= github.com/sigurn/crc8 v0.0.0-20220107193325-2243fe600f9f/go.mod h1:vQhwQ4meQEDfahT5kd61wLAF5AAeh5ZPLVI4JJ/tYo8= github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= @@ -70,34 +71,35 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/suapapa/go_eddystone v1.3.1/go.mod h1:bXC11TfJOS+3g3q/Uzd7FKd5g62STQEfeEIhcKe4Qy8= github.com/tinygo-org/cbgo v0.0.4 h1:3D76CRYbH03Rudi8sEgs/YO0x3JIMdyq8jlQtk/44fU= github.com/tinygo-org/cbgo v0.0.4/go.mod h1:7+HgWIHd4nbAz0ESjGlJ1/v9LDU1Ox8MGzP9mah/fLk= github.com/warthog618/go-gpiosim v0.1.0 h1:2rTMTcKUVZxpUuvRKsagnKAbKpd3Bwffp87xywEDVGI= -github.com/warthog618/gpiod v0.8.3 h1:hGFm/zf5PUyXU2LBG4fiZyRnbSSiPEajuOtQzQ3vkLo= -github.com/warthog618/gpiod v0.8.3/go.mod h1:YHsKSpTHebSDGnKNQKfQp9t/0JxQCyXyYtCF3F+78dc= +github.com/warthog618/go-gpiosim v0.1.0/go.mod h1:Ngx/LYI5toxHr4E+Vm6vTgCnt0of0tktsSuMUEJ2wCI= +github.com/warthog618/gpiod v0.8.2 h1:2HgQ9pNowPp7W77sXhX5ut5Tqq1WoS3t7bXYDxtYvxc= +github.com/warthog618/gpiod v0.8.2/go.mod h1:O7BNpHjCn/4YS5yFVmoFZAlY1LuYuQ8vhPf0iy/qdi4= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.bug.st/serial v1.6.2 h1:kn9LRX3sdm+WxWKufMlIRndwGfPWsH1/9lCWXQCasq8= -go.bug.st/serial v1.6.2/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= -gocv.io/x/gocv v0.39.0 h1:vWHupDE22LebZW6id2mVeT767j1YS8WqGt+ZiV7XJXE= -gocv.io/x/gocv v0.39.0/go.mod h1:zYdWMj29WAEznM3Y8NsU3A0TRq/wR/cy75jeUypThqU= +go.bug.st/serial v1.6.1 h1:VSSWmUxlj1T/YlRo2J104Zv3wJFrjHIl/T3NeruWAHY= +go.bug.st/serial v1.6.1/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= +gocv.io/x/gocv v0.35.0 h1:Qaxb5KdVyy8Spl4S4K0SMZ6CVmKtbfoSGQAxRD3FZlw= +gocv.io/x/gocv v0.35.0/go.mod h1:oc6FvfYqfBp99p+yOEzs9tbYF9gOrAQSeL/dyIPefJU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -105,8 +107,8 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= diff --git a/platforms/adaptors/pwmpinsadaptor.go b/platforms/adaptors/pwmpinsadaptor.go index 16388bba2..25978a40c 100644 --- a/platforms/adaptors/pwmpinsadaptor.go +++ b/platforms/adaptors/pwmpinsadaptor.go @@ -135,14 +135,14 @@ func WithPWMDefaultPeriodForPin(pin string, periodNanoSec uint32) pwmPinsDefault // WithPWMServoDutyCycleRangeForPin set new values for range of duty cycle for servo calls, which replaces the default // 0.5-2.5 ms range. The given duration values will be internally converted to nanoseconds. -func WithPWMServoDutyCycleRangeForPin(pin string, min, max time.Duration) pwmPinsServoDutyScaleForPinOption { - return pwmPinsServoDutyScaleForPinOption{id: pin, min: min, max: max} +func WithPWMServoDutyCycleRangeForPin(pin string, minimum, maximum time.Duration) pwmPinsServoDutyScaleForPinOption { + return pwmPinsServoDutyScaleForPinOption{id: pin, min: minimum, max: maximum} } // WithPWMServoAngleRangeForPin set new values for range of angle for servo calls, which replaces // the default 0.0-180.0° range. -func WithPWMServoAngleRangeForPin(pin string, min, max float64) pwmPinsServoAngleScaleForPinOption { - return pwmPinsServoAngleScaleForPinOption{id: pin, minDegree: min, maxDegree: max} +func WithPWMServoAngleRangeForPin(pin string, minimum, maximum float64) pwmPinsServoAngleScaleForPinOption { + return pwmPinsServoAngleScaleForPinOption{id: pin, minDegree: minimum, maxDegree: maximum} } // Connect prepare new connection to PWM pins. @@ -384,6 +384,8 @@ func setPeriod(pin gobot.PWMPinner, period uint32, adjustDuty bool) error { if err != nil { return fmt.Errorf("%s with '%v'", errorBase, err) } + + //nolint:gosec // TODO: fix later duty := uint32(uint64(oldDuty) * uint64(period) / uint64(oldPeriod)) // the order depends on value (duty must not be bigger than period in any situation) diff --git a/platforms/adaptors/pwmpinsadaptor_test.go b/platforms/adaptors/pwmpinsadaptor_test.go index 3dfc595fe..400674d97 100644 --- a/platforms/adaptors/pwmpinsadaptor_test.go +++ b/platforms/adaptors/pwmpinsadaptor_test.go @@ -2,6 +2,7 @@ package adaptors import ( + "errors" "fmt" "runtime" "strconv" @@ -416,7 +417,7 @@ func Test_PWMPin(t *testing.T) { "/sys/devices/platform/ff680020.pwm/pwm/pwmchip3/pwm44/polarity: no such file", }, "translate_error": { - translate: func(string) (string, int, error) { return "", -1, fmt.Errorf(translateErr) }, + translate: func(string) (string, int, error) { return "", -1, errors.New(translateErr) }, wantErr: translateErr, }, } diff --git a/platforms/dexter/gopigo3/driver.go b/platforms/dexter/gopigo3/driver.go index 0edbdb1d2..d05ca6bee 100644 --- a/platforms/dexter/gopigo3/driver.go +++ b/platforms/dexter/gopigo3/driver.go @@ -355,7 +355,7 @@ func (d *Driver) ServoWrite(port string, angle byte) error { angle = 180 } pulseWidth := ((1500 - (pulseWidthRange / 2)) + ((pulseWidthRange / 180) * int(angle))) - return d.SetServo(srvo, uint16(pulseWidth)) + return d.SetServo(srvo, uint16(pulseWidth)) //nolint:gosec // TODO: fix later } // SetMotorPower sets a motor's power from -128 to 127. @@ -438,7 +438,7 @@ func (d *Driver) GetMotorStatus(motor Motor) (flags uint8, power uint16, encoder e := binary.LittleEndian.Uint32(enc) encoder = int(e) if e&0x80000000 == 0x80000000 { - encoder = int(uint64(e) - 0x100000000) + encoder = int(uint64(e) - 0x100000000) //nolint:gosec // TODO: fix later } // get dps dpsRaw := make([]byte, 4) @@ -557,7 +557,7 @@ func (d *Driver) PwmWrite(pin string, val byte) error { return err } val64 := math.Float64frombits(uint64(val)) - dutyCycle := uint16(math.Float64bits((100.0 / 255.0) * val64)) + dutyCycle := uint16(math.Float64bits((100.0 / 255.0) * val64)) //nolint:gosec // TODO: fix later return d.SetPWMDuty(grovePin, dutyCycle) } diff --git a/platforms/digispark/README.md b/platforms/digispark/README.md index 80a953aff..b53687033 100644 --- a/platforms/digispark/README.md +++ b/platforms/digispark/README.md @@ -66,6 +66,8 @@ func main() { } ``` +Build your application with build tag "libusb". + ## How to Connect If your Digispark already has the Little Wire protocol firmware installed, you can connect right away with Gobot. diff --git a/platforms/digispark/digispark_adaptor.go b/platforms/digispark/digispark_adaptor.go index fd69498d5..44e139221 100644 --- a/platforms/digispark/digispark_adaptor.go +++ b/platforms/digispark/digispark_adaptor.go @@ -1,3 +1,6 @@ +//go:build libusb +// +build libusb + package digispark import ( @@ -58,10 +61,12 @@ func (d *Adaptor) DigitalWrite(pin string, level byte) error { return err } + //nolint:gosec // TODO: fix later if err := d.littleWire.pinMode(uint8(p), 0); err != nil { return err } + //nolint:gosec // TODO: fix later return d.littleWire.digitalWrite(uint8(p), level) } @@ -98,6 +103,7 @@ func (d *Adaptor) GetI2cConnection(address int, bus int) (i2c.Connection, error) if bus != 0 { return nil, fmt.Errorf("Invalid bus number %d, only 0 is supported", bus) } + //nolint:gosec // TODO: fix later c := NewDigisparkI2cConnection(d, uint8(address)) if err := c.Init(); err != nil { return nil, err diff --git a/platforms/digispark/digispark_adaptor_test.go b/platforms/digispark/digispark_adaptor_test.go index 677018fa6..cbf74fbde 100644 --- a/platforms/digispark/digispark_adaptor_test.go +++ b/platforms/digispark/digispark_adaptor_test.go @@ -1,3 +1,6 @@ +//go:build libusb +// +build libusb + //nolint:forcetypeassert // ok here package digispark diff --git a/platforms/digispark/digispark_i2c.go b/platforms/digispark/digispark_i2c.go index b63f50f1e..7a178aa3f 100644 --- a/platforms/digispark/digispark_i2c.go +++ b/platforms/digispark/digispark_i2c.go @@ -1,3 +1,6 @@ +//go:build libusb +// +build libusb + package digispark import ( @@ -155,8 +158,8 @@ func (c *digisparkI2cConnection) WriteWordData(reg uint8, val uint16) error { c.mtx.Lock() defer c.mtx.Unlock() - low := uint8(val & 0xff) - high := uint8((val >> 8) & 0xff) + low := uint8(val & 0xff) //nolint:gosec // ok here + high := uint8((val >> 8) & 0xff) //nolint:gosec // ok here buf := []byte{reg, low, high} return c.writeAndCheckCount(buf, true) } diff --git a/platforms/digispark/digispark_i2c_test.go b/platforms/digispark/digispark_i2c_test.go index b14b7fb38..5c603f501 100644 --- a/platforms/digispark/digispark_i2c_test.go +++ b/platforms/digispark/digispark_i2c_test.go @@ -1,3 +1,6 @@ +//go:build libusb +// +build libusb + //nolint:forcetypeassert // ok here package digispark diff --git a/platforms/digispark/doc.go b/platforms/digispark/doc.go index a62d3a2db..3105d4105 100644 --- a/platforms/digispark/doc.go +++ b/platforms/digispark/doc.go @@ -1,3 +1,6 @@ +//go:build libusb +// +build libusb + /* Package digispark provides the Gobot adaptor for the Digispark ATTiny-based USB development board. diff --git a/platforms/dji/tello/driver.go b/platforms/dji/tello/driver.go index 0510c0316..ffe23fe91 100644 --- a/platforms/dji/tello/driver.go +++ b/platforms/dji/tello/driver.go @@ -890,7 +890,7 @@ func (d *Driver) SendStickCommand() error { axis4 := int16(660.0*d.lx + 1024.0) // speed control - axis5 := int16(d.throttle) + axis5 := int16(d.throttle) //nolint:gosec // TODO: fix later packedAxis := int64(axis1)&0x7FF | int64(axis2&0x7FF)<<11 | 0x7FF&int64(axis3)<<22 | 0x7FF&int64(axis4)<<33 | int64(axis5)<<44 @@ -954,18 +954,23 @@ func (d *Driver) SendDateTime() error { if err := binary.Write(buf, binary.LittleEndian, byte(0x00)); err != nil { return err } + //nolint:gosec // TODO: fix later if err := binary.Write(buf, binary.LittleEndian, int16(now.Hour())); err != nil { return err } + //nolint:gosec // TODO: fix later if err := binary.Write(buf, binary.LittleEndian, int16(now.Minute())); err != nil { return err } + //nolint:gosec // TODO: fix later if err := binary.Write(buf, binary.LittleEndian, int16(now.Second())); err != nil { return err } + //nolint:gosec // TODO: fix later if err := binary.Write(buf, binary.LittleEndian, int16(now.UnixNano()/int64(time.Millisecond)&0xff)); err != nil { return err } + //nolint:gosec // TODO: fix later if err := binary.Write(buf, binary.LittleEndian, int16(now.UnixNano()/int64(time.Millisecond)>>8)); err != nil { return err } @@ -1100,7 +1105,7 @@ func (d *Driver) createPacket(cmd int16, pktType byte, pktLen int16) (*bytes.Buf func (d *Driver) connectionString() string { x, _ := strconv.Atoi(d.videoPort) b := [2]byte{} - binary.LittleEndian.PutUint16(b[:], uint16(x)) + binary.LittleEndian.PutUint16(b[:], uint16(x)) //nolint:gosec // TODO: fix later res := fmt.Sprintf("conn_req:%s", b) return res } diff --git a/platforms/firmata/client/client.go b/platforms/firmata/client/client.go index 0f0f6f246..6c000102d 100644 --- a/platforms/firmata/client/client.go +++ b/platforms/firmata/client/client.go @@ -278,14 +278,14 @@ func (b *Client) DigitalWrite(pin int, value int) error { } // ServoConfig sets the min and max pulse width for servo PWM range -func (b *Client) ServoConfig(pin int, max int, min int) error { +func (b *Client) ServoConfig(pin int, maximum int, minimum int) error { ret := []byte{ ServoConfig, byte(pin), - byte(min & 0x7F), - byte((min >> 7) & 0x7F), - byte(max & 0x7F), - byte((max >> 7) & 0x7F), + byte(minimum & 0x7F), + byte((minimum >> 7) & 0x7F), + byte(maximum & 0x7F), + byte((maximum >> 7) & 0x7F), } return b.WriteSysex(ret) } @@ -410,6 +410,7 @@ func (b *Client) process() error { if len(b.analogPins) > pin { if len(b.pins) > b.analogPins[pin] { + //nolint:gosec // TODO: fix later b.pins[b.analogPins[pin]].Value = int(value) b.Publish(b.Event(fmt.Sprintf("AnalogRead%v", pin)), b.pins[b.analogPins[pin]].Value) } @@ -500,9 +501,11 @@ func (b *Client) process() error { b.pins[pin].State = int(currentBuffer[4]) if len(currentBuffer) > 6 { + //nolint:gosec // TODO: fix later b.pins[pin].State = int(uint(b.pins[pin].State) | uint(currentBuffer[5])<<7) } if len(currentBuffer) > 7 { + //nolint:gosec // TODO: fix later b.pins[pin].State = int(uint(b.pins[pin].State) | uint(currentBuffer[6])<<14) } diff --git a/platforms/firmata/firmata_adaptor.go b/platforms/firmata/firmata_adaptor.go index 888f6a13b..0c704bb2c 100644 --- a/platforms/firmata/firmata_adaptor.go +++ b/platforms/firmata/firmata_adaptor.go @@ -28,7 +28,7 @@ type firmataBoard interface { I2cRead(address int, numBytes int) error I2cWrite(address int, data []byte) error I2cConfig(delay int) error - ServoConfig(pin int, max int, min int) error + ServoConfig(pin int, maximum int, minimum int) error WriteSysex(data []byte) error gobot.Eventer } @@ -126,13 +126,13 @@ func (f *Adaptor) Name() string { return f.name } func (f *Adaptor) SetName(n string) { f.name = n } // ServoConfig sets the pulse width in microseconds for a pin attached to a servo -func (f *Adaptor) ServoConfig(pin string, min, max int) error { +func (f *Adaptor) ServoConfig(pin string, minimum, maximum int) error { p, err := strconv.Atoi(pin) if err != nil { return err } - return f.Board.ServoConfig(p, max, min) + return f.Board.ServoConfig(p, maximum, minimum) } // ServoWrite writes the 0-180 degree angle to the specified pin. diff --git a/platforms/firmata/firmata_i2c.go b/platforms/firmata/firmata_i2c.go index e4c5d8714..407091026 100644 --- a/platforms/firmata/firmata_i2c.go +++ b/platforms/firmata/firmata_i2c.go @@ -140,8 +140,8 @@ func (c *firmataI2cConnection) WriteWordData(reg uint8, val uint16) error { c.mtx.Lock() defer c.mtx.Unlock() - low := uint8(val & 0xff) - high := uint8((val >> 8) & 0xff) + low := uint8(val & 0xff) //nolint:gosec // ok here + high := uint8((val >> 8) & 0xff) //nolint:gosec // ok here buf := []byte{reg, low, high} return c.writeAndCheckCount(buf) } diff --git a/platforms/firmata/firmata_i2c_test.go b/platforms/firmata/firmata_i2c_test.go index 8b06ca6f6..0b5247e73 100644 --- a/platforms/firmata/firmata_i2c_test.go +++ b/platforms/firmata/firmata_i2c_test.go @@ -1,7 +1,7 @@ //go:build !windows // +build !windows -//nolint:forcetypeassert // ok here +//nolint:forcetypeassert,gosec // ok here package firmata import ( diff --git a/platforms/intel-iot/curie/imu_driver.go b/platforms/intel-iot/curie/imu_driver.go index 185e6bc0f..340c37d6c 100644 --- a/platforms/intel-iot/curie/imu_driver.go +++ b/platforms/intel-iot/curie/imu_driver.go @@ -203,9 +203,9 @@ func parseAccelerometerData(data []byte) (*AccelerometerData, error) { if len(data) < 9 { return nil, errors.New("Invalid data") } - x := int16(uint16(data[3]) | uint16(data[4])<<7) - y := int16(uint16(data[5]) | uint16(data[6])<<7) - z := int16(uint16(data[7]) | uint16(data[8])<<7) + x := int16(uint16(data[3]) | uint16(data[4])<<7) //nolint:gosec // ok here + y := int16(uint16(data[5]) | uint16(data[6])<<7) //nolint:gosec // ok here + z := int16(uint16(data[7]) | uint16(data[8])<<7) //nolint:gosec // ok here res := &AccelerometerData{X: x, Y: y, Z: z} return res, nil @@ -215,9 +215,9 @@ func parseGyroscopeData(data []byte) (*GyroscopeData, error) { if len(data) < 9 { return nil, errors.New("Invalid data") } - x := int16(uint16(data[3]) | uint16(data[4])<<7) - y := int16(uint16(data[5]) | uint16(data[6])<<7) - z := int16(uint16(data[7]) | uint16(data[8])<<7) + x := int16(uint16(data[3]) | uint16(data[4])<<7) //nolint:gosec // ok here + y := int16(uint16(data[5]) | uint16(data[6])<<7) //nolint:gosec // ok here + z := int16(uint16(data[7]) | uint16(data[8])<<7) //nolint:gosec // ok here res := &GyroscopeData{X: x, Y: y, Z: z} return res, nil @@ -227,8 +227,8 @@ func parseTemperatureData(data []byte) (float32, error) { if len(data) < 8 { return 0, errors.New("Invalid data") } - t1 := int16(uint16(data[3]) | uint16(data[4])<<7) - t2 := int16(uint16(data[5]) | uint16(data[6])<<7) + t1 := int16(uint16(data[3]) | uint16(data[4])<<7) //nolint:gosec // ok here + t2 := int16(uint16(data[5]) | uint16(data[6])<<7) //nolint:gosec // ok here res := (float32(t1+(t2*8)) / 512.0) + 23.0 return res, nil @@ -248,7 +248,7 @@ func parseStepData(data []byte) (int16, error) { return 0, errors.New("Invalid data") } - res := int16(uint16(data[3]) | uint16(data[4])<<7) + res := int16(uint16(data[3]) | uint16(data[4])<<7) //nolint:gosec // ok here return res, nil } @@ -265,13 +265,13 @@ func parseMotionData(data []byte) (*MotionData, error) { if len(data) < 16 { return nil, errors.New("Invalid data") } - ax := int16(uint16(data[3]) | uint16(data[4])<<7) - ay := int16(uint16(data[5]) | uint16(data[6])<<7) - az := int16(uint16(data[7]) | uint16(data[8])<<7) + ax := int16(uint16(data[3]) | uint16(data[4])<<7) //nolint:gosec // ok here + ay := int16(uint16(data[5]) | uint16(data[6])<<7) //nolint:gosec // ok here + az := int16(uint16(data[7]) | uint16(data[8])<<7) //nolint:gosec // ok here - gx := int16(uint16(data[9]) | uint16(data[10])<<7) - gy := int16(uint16(data[11]) | uint16(data[12])<<7) - gz := int16(uint16(data[13]) | uint16(data[14])<<7) + gx := int16(uint16(data[9]) | uint16(data[10])<<7) //nolint:gosec // ok here + gy := int16(uint16(data[11]) | uint16(data[12])<<7) //nolint:gosec // ok here + gz := int16(uint16(data[13]) | uint16(data[14])<<7) //nolint:gosec // ok here res := &MotionData{AX: ax, AY: ay, AZ: az, GX: gx, GY: gy, GZ: gz} return res, nil diff --git a/platforms/joystick/bin/scanner.go b/platforms/joystick/bin/scanner.go index 6bda8e447..8554c9871 100644 --- a/platforms/joystick/bin/scanner.go +++ b/platforms/joystick/bin/scanner.go @@ -39,6 +39,7 @@ func readJoystick(js joystick.Joystick) { printAt(1, 5, "Buttons:") for button := 0; button < js.ButtonCount(); button++ { + //nolint:gosec // TODO: fix later if jinfo.Buttons&(1<> 8) ^ (uint16(tmp) << 8) ^ (uint16(tmp) << 3) ^ (uint16(tmp) >> 4) return crcAccum diff --git a/platforms/mavlink/mavlink_adaptor_test.go b/platforms/mavlink/mavlink_adaptor_test.go index da18a6c93..2a279a0b2 100644 --- a/platforms/mavlink/mavlink_adaptor_test.go +++ b/platforms/mavlink/mavlink_adaptor_test.go @@ -52,7 +52,7 @@ func (nullReadWriteCloser) Close() error { func initTestMavlinkAdaptor() *Adaptor { m := NewAdaptor("/dev/null") m.sp = nullReadWriteCloser{} - m.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil } + m.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil } //nolint:nilnil // ok for tests return m } diff --git a/platforms/mavlink/mavlink_driver_test.go b/platforms/mavlink/mavlink_driver_test.go index f1efef54b..624a2bb77 100644 --- a/platforms/mavlink/mavlink_driver_test.go +++ b/platforms/mavlink/mavlink_driver_test.go @@ -1,4 +1,4 @@ -//nolint:forcetypeassert // ok here +//nolint:forcetypeassert,nilnil // ok here package mavlink import ( diff --git a/platforms/opencv/README.md b/platforms/opencv/README.md index c89e25b92..8f7f64c18 100644 --- a/platforms/opencv/README.md +++ b/platforms/opencv/README.md @@ -69,3 +69,5 @@ func main() { } } ``` + +Build your application with build tag "gocv". diff --git a/platforms/opencv/camera_driver.go b/platforms/opencv/camera_driver.go index 9a4e8136c..d84f3e77d 100644 --- a/platforms/opencv/camera_driver.go +++ b/platforms/opencv/camera_driver.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( @@ -41,7 +44,7 @@ func NewCameraDriver(source interface{}) *CameraDriver { default: return errors.New("Unknown camera source") } - return + return nil }, } @@ -72,7 +75,7 @@ func (c *CameraDriver) Start() error { } } }() - return + return nil } // Halt stops camera driver diff --git a/platforms/opencv/camera_driver_test.go b/platforms/opencv/camera_driver_test.go index 81ecacb7f..d37811366 100644 --- a/platforms/opencv/camera_driver_test.go +++ b/platforms/opencv/camera_driver_test.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( diff --git a/platforms/opencv/helpers_test.go b/platforms/opencv/helpers_test.go index b8c7d63f2..e04299f6e 100644 --- a/platforms/opencv/helpers_test.go +++ b/platforms/opencv/helpers_test.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( diff --git a/platforms/opencv/utils.go b/platforms/opencv/utils.go index 7e2641a19..b0dedb7a7 100644 --- a/platforms/opencv/utils.go +++ b/platforms/opencv/utils.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( diff --git a/platforms/opencv/utils_test.go b/platforms/opencv/utils_test.go index 775f2df60..eb4879eb8 100644 --- a/platforms/opencv/utils_test.go +++ b/platforms/opencv/utils_test.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( diff --git a/platforms/opencv/window_driver.go b/platforms/opencv/window_driver.go index a1130e521..943dd2756 100644 --- a/platforms/opencv/window_driver.go +++ b/platforms/opencv/window_driver.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( @@ -39,11 +42,11 @@ func (w *WindowDriver) Connection() gobot.Connection { return nil } // Start starts window thread and driver func (w *WindowDriver) Start() error { w.start(w) - return + return nil } // Halt returns true if camera is halted successfully -func (w *WindowDriver) Halt() error { return } +func (w *WindowDriver) Halt() error { return nil } // ShowImage displays image in window func (w *WindowDriver) ShowImage(img gocv.Mat) { diff --git a/platforms/opencv/window_driver_test.go b/platforms/opencv/window_driver_test.go index 36bebcf90..042162233 100644 --- a/platforms/opencv/window_driver_test.go +++ b/platforms/opencv/window_driver_test.go @@ -1,3 +1,6 @@ +//go:build gocv +// +build gocv + package opencv import ( diff --git a/platforms/parrot/bebop/client/client.go b/platforms/parrot/bebop/client/client.go index fc4c391c6..81da02887 100644 --- a/platforms/parrot/bebop/client/client.go +++ b/platforms/parrot/bebop/client/client.go @@ -435,30 +435,35 @@ func (b *Bebop) generatePcmd() *bytes.Buffer { cmd.Write(tmp.Bytes()) tmp = &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(tmp, binary.LittleEndian, uint8(b.Pcmd.Flag)); err != nil { panic(err) } cmd.Write(tmp.Bytes()) tmp = &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(tmp, binary.LittleEndian, int8(b.Pcmd.Roll)); err != nil { panic(err) } cmd.Write(tmp.Bytes()) tmp = &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(tmp, binary.LittleEndian, int8(b.Pcmd.Pitch)); err != nil { panic(err) } cmd.Write(tmp.Bytes()) tmp = &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(tmp, binary.LittleEndian, int8(b.Pcmd.Yaw)); err != nil { panic(err) } cmd.Write(tmp.Bytes()) tmp = &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(tmp, binary.LittleEndian, int8(b.Pcmd.Gaz)); err != nil { panic(err) } @@ -482,6 +487,7 @@ func (b *Bebop) createAck(frame NetworkFrame) *bytes.Buffer { // libARNetwork/Sources/ARNETWORK_Manager.h#ARNETWORK_Manager_IDOutputToIDAck // + //nolint:gosec // TODO: fix later return b.nwFrameGenerator.generate(bytes.NewBuffer([]byte{uint8(frame.Seq)}), ARNETWORKAL_FRAME_TYPE_ACK, byte(uint16(frame.Id)+(ARNETWORKAL_MANAGER_DEFAULT_ID_MAX/2)), @@ -755,14 +761,17 @@ func (b *Bebop) createARStreamACK(frame ARStreamFrame) *bytes.Buffer { b.tmpFrame.fragments[frame.FragmentNumber] = frame.Frame if frame.FragmentNumber < 64 { + //nolint:gosec // TODO: fix later b.tmpFrame.arstreamACK.LowPacketsAck |= uint64(1) << uint64(frame.FragmentNumber) } else { + //nolint:gosec // TODO: fix later b.tmpFrame.arstreamACK.HighPacketsAck |= uint64(1) << uint64(frame.FragmentNumber-64) } ackPacket := &bytes.Buffer{} tmp := &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(tmp, binary.LittleEndian, uint16(b.tmpFrame.arstreamACK.FrameNumber)); err != nil { panic(err) } diff --git a/platforms/parrot/bebop/client/networkframegenerator.go b/platforms/parrot/bebop/client/networkframegenerator.go index af06e356b..44b189428 100644 --- a/platforms/parrot/bebop/client/networkframegenerator.go +++ b/platforms/parrot/bebop/client/networkframegenerator.go @@ -40,11 +40,7 @@ func (nwg *nwFrameGenerator) generate(cmd *bytes.Buffer, frameType byte, id byte nwg.seq[id] = 0 } - nwg.seq[id]++ - - if nwg.seq[id] > 255 { - nwg.seq[id] = 0 - } + nwg.seq[id]++ // automatically rollover to 0 when > 255 is fine ret := &bytes.Buffer{} ret.WriteByte(frameType) @@ -52,6 +48,7 @@ func (nwg *nwFrameGenerator) generate(cmd *bytes.Buffer, frameType byte, id byte ret.WriteByte(nwg.seq[id]) size := &bytes.Buffer{} + //nolint:gosec // TODO: fix later if err := binary.Write(size, binary.LittleEndian, uint32(cmd.Len()+nwg.hlen)); err != nil { panic(err) } diff --git a/platforms/particle/adaptor_test.go b/platforms/particle/adaptor_test.go index 69fc29675..6ddbcfb14 100644 --- a/platforms/particle/adaptor_test.go +++ b/platforms/particle/adaptor_test.go @@ -29,6 +29,7 @@ func getDummyResponseForPath(t *testing.T, path string, dummyResponse string) *h return createTestServer(func(w http.ResponseWriter, r *http.Request) { actualPath := "/v1/devices" + path if r.URL.Path != actualPath { + //nolint:testifylint // TODO: fix later require.Fail(t, "Path doesn't match, expected %#v, got %#v", actualPath, r.URL.Path) } _, _ = w.Write(dummyData) @@ -48,6 +49,7 @@ func getDummyResponseForPathWithParams( return createTestServer(func(w http.ResponseWriter, r *http.Request) { actualPath := "/v1/devices" + path if r.URL.Path != actualPath { + //nolint:testifylint // TODO: fix later require.Fail(t, "Path doesn't match, expected %#v, got %#v", actualPath, r.URL.Path) } diff --git a/system/digitalpin_gpiod.go b/system/digitalpin_gpiod.go index 7ebe9f85c..8c81477bb 100644 --- a/system/digitalpin_gpiod.go +++ b/system/digitalpin_gpiod.go @@ -1,6 +1,7 @@ package system import ( + "errors" "fmt" "log" "strconv" @@ -117,7 +118,8 @@ func (d *digitalPinGpiod) Unexport() error { if len(errs) == 0 { return nil } - return fmt.Errorf(strings.Join(errs, ",")) + + return errors.New(strings.Join(errs, ",")) } // Write writes the given value to the character device. Implements the interface gobot.DigitalPinner. diff --git a/system/digitalpin_poll_test.go b/system/digitalpin_poll_test.go index d72011008..0c8a0c5eb 100644 --- a/system/digitalpin_poll_test.go +++ b/system/digitalpin_poll_test.go @@ -1,7 +1,7 @@ package system import ( - "fmt" + "errors" "sync" "testing" "time" @@ -150,7 +150,7 @@ func Test_startEdgePolling(t *testing.T) { readVal := tc.simulateReadValues[numCallsRead-1] var err error if readVal.err != "" { - err = fmt.Errorf(readVal.err) + err = errors.New(readVal.err) } if numCallsRead >= len(tc.simulateReadValues) { close(quitChan) // ensure no further read call diff --git a/system/fs_mock_test.go b/system/fs_mock_test.go index 849c8e4ee..b271628a5 100644 --- a/system/fs_mock_test.go +++ b/system/fs_mock_test.go @@ -80,7 +80,7 @@ func TestMockFilesystemWrite(t *testing.T) { _, _ = f2.WriteString("testing") // Was written. - assert.Greater(t, f1.Seq, 0) + assert.Positive(t, f1.Seq) assert.Equal(t, "testing", f1.Contents) } @@ -98,7 +98,7 @@ func TestMockFilesystemRead(t *testing.T) { n, _ := f2.Read(buffer) // Was read. - assert.Greater(t, f1.Seq, 0) + assert.Positive(t, f1.Seq) assert.Equal(t, 3, n) assert.Equal(t, "Yip", string(buffer[:3])) diff --git a/system/i2c_device.go b/system/i2c_device.go index 2a3d83b14..f941424ba 100644 --- a/system/i2c_device.go +++ b/system/i2c_device.go @@ -382,6 +382,7 @@ func (d *i2cDevice) syscallIoctl(signal uintptr, payload unsafe.Pointer, address if err := d.openFileLazy(sender); err != nil { return err } + //nolint:gosec // TODO: fix later if _, _, errno := d.sys.syscall(Syscall_SYS_IOCTL, d.file, signal, payload, uint16(address)); errno != 0 { return fmt.Errorf("%s failed with syscall.Errno %v", sender, errno) } diff --git a/system/i2c_device_test.go b/system/i2c_device_test.go index 95725899d..bed618266 100644 --- a/system/i2c_device_test.go +++ b/system/i2c_device_test.go @@ -1,3 +1,4 @@ +//nolint:gosec // ok for test package system import ( diff --git a/system/pwmpin_sysfs.go b/system/pwmpin_sysfs.go index 859110498..4606717da 100644 --- a/system/pwmpin_sysfs.go +++ b/system/pwmpin_sysfs.go @@ -139,7 +139,7 @@ func (p *pwmPinSysFs) Period() (uint32, error) { if err != nil { return 0, fmt.Errorf(pwmPinErrorPattern, "Period", p.pin, err) } - + //nolint:gosec // TODO: fix later return uint32(val), nil } @@ -161,7 +161,7 @@ func (p *pwmPinSysFs) DutyCycle() (uint32, error) { if err != nil { return 0, fmt.Errorf(pwmPinErrorPattern, "DutyCycle", p.pin, err) } - + //nolint:gosec // TODO: fix later return uint32(val), err } diff --git a/utils.go b/utils.go index 36e58bb8d..485cb57d4 100644 --- a/utils.go +++ b/utils.go @@ -30,27 +30,27 @@ func After(t time.Duration, f func()) { time.AfterFunc(t, f) } -// Rand returns a positive random int up to max -func Rand(max int) int { - i, _ := rand.Int(rand.Reader, big.NewInt(int64(max))) +// Rand returns a positive random int up to maximum +func Rand(maximum int) int { + i, _ := rand.Int(rand.Reader, big.NewInt(int64(maximum))) return int(i.Int64()) } -// FromScale returns a converted input from min, max to 0.0...1.0. -func FromScale(input, min, max float64) float64 { - return (input - math.Min(min, max)) / (math.Max(min, max) - math.Min(min, max)) +// FromScale returns a converted input from minimum, maximum to 0.0...1.0. +func FromScale(input, minimum, maximum float64) float64 { + return (input - math.Min(minimum, maximum)) / (math.Max(minimum, maximum) - math.Min(minimum, maximum)) } -// ToScale returns a converted input from 0...1 to min...max scale. -// If input is less than min then ToScale returns min. -// If input is greater than max then ToScale returns max -func ToScale(input, min, max float64) float64 { - i := input*(math.Max(min, max)-math.Min(min, max)) + math.Min(min, max) +// ToScale returns a converted input from 0...1 to minimum...maximum scale. +// If input is less than minimum then ToScale returns minimum. +// If input is greater than maximum then ToScale returns maximum +func ToScale(input, minimum, maximum float64) float64 { + i := input*(math.Max(minimum, maximum)-math.Min(minimum, maximum)) + math.Min(minimum, maximum) switch { - case i < math.Min(min, max): - return math.Min(min, max) - case i > math.Max(min, max): - return math.Max(min, max) + case i < math.Min(minimum, maximum): + return math.Min(minimum, maximum) + case i > math.Max(minimum, maximum): + return math.Max(minimum, maximum) default: return i }