1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00

build(go, deps): switch to Go 1.22 and update modules (#1093)

This commit is contained in:
Thomas Kohler 2024-11-01 12:54:20 +01:00 committed by GitHub
parent fd85df03e3
commit a8f47eaae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
103 changed files with 323 additions and 282 deletions

View File

@ -14,7 +14,7 @@ version: 2
jobs:
"test_core_and_drivers_with_coverage":
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
steps:
- checkout
- run:
@ -31,7 +31,7 @@ jobs:
"test_platforms":
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
steps:
- checkout
- run:
@ -45,7 +45,7 @@ jobs:
"check_examples":
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
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:

View File

@ -22,6 +22,14 @@ If this is a new driver or adaptor:
- [ ] I have added an example to see how to setup and use it
- [ ] I have checked or build at least my new example (e.g. by run `make examples_check`)
If this is a Go version update:
- [ ] go.mod to new version updated
- [ ] modules updated (go get -u -t ./...)
- [ ] CI files updated
- [ ] linter setting and linter version (if a newer one exist) updated
- [ ] linter issues fixed or suppressed by config
If this is a PR for release:
- [ ] The PR's target branch is 'hybridgroup:release'

View File

@ -15,24 +15,24 @@ 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.22'
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
# 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"
# Note: exclude arguments, e.g. --exclude-files="my_file", will not affect the "typecheck" linter,
# at least since v1.61.0 - use build tags instead.
#args: --exclude-files="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 +40,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

View File

@ -22,41 +22,36 @@ 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:
- exportloopref # Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar
- gomnd # The linter has been renamed. Replaced by mnd.
# not used for this go version: none
# 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 +59,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 +80,10 @@ 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
- intrange # introduced with go 1.22, will simplify the range syntax
- 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++)

View File

@ -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:
@ -73,7 +73,7 @@ ifeq ($(CHECK),ON)
go vet ./$@
else ifeq ($(CHECK),FMT)
gofumpt -l -w ./$@
golangci-lint run ./$@ --fix --build-tags example --disable forcetypeassert --disable noctx
golangci-lint run ./$@ --fix --build-tags example,libusb --disable forcetypeassert --disable noctx
else
go build -o /tmp/gobot_examples/$@ ./$@
endif

View File

@ -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
}

View File

@ -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
})

View File

@ -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

View File

@ -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)
}

View File

@ -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{

View File

@ -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))
}

View File

@ -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

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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 {

View File

@ -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.

View File

@ -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

View File

@ -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
}

View File

@ -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 {

View File

@ -1,4 +1,4 @@
//nolint:forcetypeassert // ok here
//nolint:forcetypeassert,gosec // ok here
package i2c
import (

View File

@ -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
}

View File

@ -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)

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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{

View File

@ -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
}

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -13,6 +13,7 @@
NOTE: sudo is required to use BLE in Linux
*/
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -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

View File

@ -12,6 +12,7 @@
NOTE: sudo is required to use BLE in Linux
*/
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -13,6 +13,7 @@
NOTE: sudo is required to use BLE in Linux
*/
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -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)
}
}

View File

@ -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,
)

View File

@ -11,6 +11,7 @@
go run examples/firmata_pca9685.go /dev/ttyACM0
*/
//nolint:gosec // ok here
package main
import (

View File

@ -11,6 +11,7 @@
go run examples/firmata_rgb_led.go /dev/ttyACM0
*/
//nolint:gosec // ok here
package main
import (

View File

@ -11,6 +11,7 @@
go run examples/firmata_servo.go /dev/ttyACM0
*/
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
//

View File

@ -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)
}
}

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

View File

@ -4,6 +4,7 @@
//
// Do not build by default.
//nolint:gosec // ok here
package main
import (

8
go.mod
View File

@ -1,6 +1,8 @@
module gobot.io/x/gobot/v2
go 1.20
go 1.22.0
toolchain go1.22.7
require (
github.com/0xcafed00d/joystick v1.0.1
@ -15,12 +17,12 @@ require (
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
github.com/warthog618/go-gpiocdev v0.9.1
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
periph.io/x/conn/v3 v3.7.0
periph.io/x/conn/v3 v3.7.1
periph.io/x/host/v3 v3.8.2
tinygo.org/x/bluetooth v0.8.0
)

11
go.sum
View File

@ -75,9 +75,10 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
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-gpiocdev v0.9.1 h1:pwHPaqjJfhCipIQl78V+O3l9OKHivdRDdmgXYbmhuCI=
github.com/warthog618/go-gpiocdev v0.9.1/go.mod h1:dN3e3t/S2aSNC+hgigGE/dBW8jE1ONk9bDSEYfoPyl8=
github.com/warthog618/go-gpiosim v0.1.1 h1:MRAEv+T+itmw+3GeIGpQJBfanUVyg0l3JCTwHtwdre4=
github.com/warthog618/go-gpiosim v0.1.1/go.mod h1:YXsnB+I9jdCMY4YAlMSRrlts25ltjmuIsrnoUrBLdqU=
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=
@ -119,8 +120,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
periph.io/x/conn/v3 v3.7.0 h1:f1EXLn4pkf7AEWwkol2gilCNZ0ElY+bxS4WE2PQXfrA=
periph.io/x/conn/v3 v3.7.0/go.mod h1:ypY7UVxgDbP9PJGwFSVelRRagxyXYfttVh7hJZUHEhg=
periph.io/x/conn/v3 v3.7.1 h1:tMjNv3WO8jEz/ePuXl7y++2zYi8LsQ5otbmqGKy3Myg=
periph.io/x/conn/v3 v3.7.1/go.mod h1:c+HCVjkzbf09XzcqZu/t+U8Ss/2QuJj0jgRF6Nye838=
periph.io/x/host/v3 v3.8.2 h1:ayKUDzgUCN0g8+/xM9GTkWaOBhSLVcVHGTfjAOi8OsQ=
periph.io/x/host/v3 v3.8.2/go.mod h1:yFL76AesNHR68PboofSWYaQTKmvPXsQH2Apvp/ls/K4=
tinygo.org/x/bluetooth v0.8.0 h1:WmuRebsODcUUIlGhesyuNRIAEIUCErhKlrZ9K9aimdI=

View File

@ -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)

View File

@ -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,
},
}

View File

@ -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)
}

View File

@ -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.

View File

@ -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

View File

@ -1,3 +1,6 @@
//go:build libusb
// +build libusb
//nolint:forcetypeassert // ok here
package digispark

View File

@ -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)
}

View File

@ -1,3 +1,6 @@
//go:build libusb
// +build libusb
//nolint:forcetypeassert // ok here
package digispark

View File

@ -1,3 +1,6 @@
//go:build libusb
// +build libusb
/*
Package digispark provides the Gobot adaptor for the Digispark ATTiny-based USB development board.

View File

@ -1,3 +1,6 @@
//go:build libusb
// +build libusb
package digispark
//#cgo pkg-config: libusb

View File

@ -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
}

View File

@ -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)
}

View File

@ -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.

View File

@ -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)
}

View File

@ -1,7 +1,7 @@
//go:build !windows
// +build !windows
//nolint:forcetypeassert // ok here
//nolint:forcetypeassert,gosec // ok here
package firmata
import (

View File

@ -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

View File

@ -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<<uint32(button)) != 0 {
printAt(10+button, 5, "X")
printAt(1, 6, fmt.Sprintf("Button %2d Pressed", button))

View File

@ -205,9 +205,11 @@ func (j *Driver) Halt() error {
func (j *Driver) handleButtons(state js.State) error {
for button := 0; button < j.adaptor().joystick.ButtonCount(); button++ {
//nolint:gosec // TODO: fix later
buttonPressed := state.Buttons&(1<<uint32(button)) != 0
if buttonPressed != j.buttonState[button] {
j.buttonState[button] = buttonPressed
//nolint:gosec // TODO: fix later
name := j.findName(uint8(button), j.config.Buttons)
if name == "" {
return fmt.Errorf("Unknown button: %v", button)
@ -226,6 +228,7 @@ func (j *Driver) handleButtons(state js.State) error {
func (j *Driver) handleAxes(state js.State) error {
for axis := 0; axis < j.adaptor().joystick.AxisCount(); axis++ {
//nolint:gosec // TODO: fix later
name := j.findName(uint8(axis), j.config.Axis)
if name == "" {
return fmt.Errorf("Unknown Axis: %v", axis)

View File

@ -16,7 +16,7 @@ var _ gobot.Adaptor = (*Adaptor)(nil)
func initTestLeapMotionAdaptor() *Adaptor {
a := NewAdaptor("")
a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil }
a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil } //nolint:nilnil // ok for test
return a
}

View File

@ -28,7 +28,7 @@ var sequence uint16 = 0
func generateSequence() uint8 {
sequence = (sequence + 1) % 256
return uint8(sequence)
return uint8(sequence) //nolint:gosec // ok here
}
// The MAVLinkMessage interface is implemented by MAVLink messages
@ -194,7 +194,7 @@ func crcAccumulate(data uint8, crcAccum uint16) uint16 {
/*Accumulate one byte of data into the CRC*/
var tmp uint8
tmp = data ^ (uint8)(crcAccum&0xff)
tmp = data ^ (uint8)(crcAccum&0xff) //nolint:gosec // ok here
tmp ^= (tmp << 4)
crcAccum = (crcAccum >> 8) ^ (uint16(tmp) << 8) ^ (uint16(tmp) << 3) ^ (uint16(tmp) >> 4)
return crcAccum

View File

@ -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
}

View File

@ -1,4 +1,4 @@
//nolint:forcetypeassert // ok here
//nolint:forcetypeassert,nilnil // ok here
package mavlink
import (

View File

@ -69,3 +69,5 @@ func main() {
}
}
```
Build your application with build tag "gocv".

View File

@ -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

View File

@ -1,3 +1,6 @@
//go:build gocv
// +build gocv
package opencv
import (

View File

@ -1,3 +1,6 @@
//go:build gocv
// +build gocv
package opencv
import (

View File

@ -1,3 +1,6 @@
//go:build gocv
// +build gocv
package opencv
import (

View File

@ -1,3 +1,6 @@
//go:build gocv
// +build gocv
package opencv
import (

View File

@ -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) {

View File

@ -1,3 +1,6 @@
//go:build gocv
// +build gocv
package opencv
import (

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -1,13 +1,14 @@
package system
import (
"errors"
"fmt"
"log"
"strconv"
"strings"
"time"
"github.com/warthog618/gpiod"
gpiod "github.com/warthog618/go-gpiocdev"
"gobot.io/x/gobot/v2"
)
@ -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.

View File

@ -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

View File

@ -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]))

View File

@ -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)
}

Some files were not shown because too many files have changed in this diff Show More