Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

module periph.io/x/cmd

go 1.22.6
go 1.23.0

require (
golang.org/x/image v0.23.0
periph.io/x/conn/v3 v3.7.1
golang.org/x/image v0.25.0
periph.io/x/conn/v3 v3.7.2
periph.io/x/d2xx v0.1.1
periph.io/x/devices/v3 v3.7.3
periph.io/x/devices/v3 v3.7.4
periph.io/x/host/v3 v3.8.3
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=
github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60=
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
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=
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
periph.io/x/conn/v3 v3.7.2 h1:qt9dE6XGP5ljbFnCKRJ9OOCoiOyBGlw7JZgoi72zZ1s=
periph.io/x/conn/v3 v3.7.2/go.mod h1:Ao0b4sFRo4QOx6c1tROJU1fLJN1hUIYggjOrkIVnpGg=
periph.io/x/d2xx v0.1.1 h1:LHp+u+qAWLB5THrTT/AzyjdvfUhllvDF5wBJP7uvn+U=
periph.io/x/d2xx v0.1.1/go.mod h1:rLM321G11Fc14Pp088khBkmXb70Pxx/kCPaIK7uRUBc=
periph.io/x/devices/v3 v3.7.3 h1:N/mTFOwDoelfrPgVvN/6ZNCM++ym6GUYBMaTlh3ljKI=
periph.io/x/devices/v3 v3.7.3/go.mod h1:y1T7FtIcs8nYQZG2a8wglb8APSOH+UHZIsh19EBjsqc=
periph.io/x/devices/v3 v3.7.4 h1:g9CGKTtiXS9iyDFDba4sr9pYde4dy+ZCKRPuKpKJdKo=
periph.io/x/devices/v3 v3.7.4/go.mod h1:FqFG9RotW2aCkfIlAes3qxziwgjRTncTMS5cSOcizNg=
periph.io/x/host/v3 v3.8.3 h1:v90ozCFDWgEyfNElZ+JnOvq0jAdW0vmgjCUy8dYXDds=
periph.io/x/host/v3 v3.8.3/go.mod h1:uKrIpfXjELwHkwGBNe6aos//XiQ/3uxDa1P2BmLV6Ok=
37 changes: 25 additions & 12 deletions mpu9250/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"log"
"time"

"periph.io/x/conn/v3/i2c"
"periph.io/x/conn/v3/i2c/i2creg"

"periph.io/x/conn/v3/gpio/gpioreg"
"periph.io/x/host/v3"

Expand All @@ -19,6 +22,8 @@
)

var (
ifType = flag.String("iftype", "spi", "Interface Type (spi, i2c)")
i2cAddr = flag.Int("i2caddr", 0x68, "I2C Address - Default 0x68")
accRes = flag.String("accRes", "2", "Acceleration resolution (2, 4, 8, 16G)")
continuous = flag.Bool("cont", false, "Continuous read")
sensitivity int
Expand All @@ -44,16 +49,28 @@
if _, err := host.Init(); err != nil {
log.Fatal("Error initializing host", err)
}
cs := gpioreg.ByName("8")
if cs == nil {
log.Fatal("Can't initialize CS pin")

var t *mpu9250.Transport
var err error

if *ifType == "spi" {
cs := gpioreg.ByName("8")
if cs == nil {
log.Fatal("Can't initialize CS pin")
}
t, err = mpu9250.NewSpiTransport("", cs)
} else {
var bus i2c.Bus
bus, err = i2creg.Open("")
if err == nil {
t, err = mpu9250.NewI2cTransport(bus, uint16(*i2cAddr))
}

Check warning on line 67 in mpu9250/main.go

View check run for this annotation

Codecov / codecov/patch

mpu9250/main.go#L53-L67

Added lines #L53 - L67 were not covered by tests
}
t, err := mpu9250.NewSpiTransport("", cs)
if err != nil {
log.Fatal("Can't initialize SPI bus ", err)
log.Fatalf("Can't initialize %s bus: %s", *ifType, err)

Check warning on line 70 in mpu9250/main.go

View check run for this annotation

Codecov / codecov/patch

mpu9250/main.go#L70

Added line #L70 was not covered by tests
}

dev, err := mpu9250.New(t)
dev, err := mpu9250.New(*t)

Check warning on line 73 in mpu9250/main.go

View check run for this annotation

Codecov / codecov/patch

mpu9250/main.go#L73

Added line #L73 was not covered by tests
if err != nil {
log.Fatal(err)
}
Expand All @@ -75,15 +92,11 @@

st, err := dev.SelfTest()
if err != nil {
log.Fatal("Self test failed", err)
log.Fatal("Self test failed: ", err)

Check warning on line 95 in mpu9250/main.go

View check run for this annotation

Codecov / codecov/patch

mpu9250/main.go#L95

Added line #L95 was not covered by tests
}

if err = dev.Calibrate(); err != nil {
log.Fatal("Can't calibrate", err)
}

if err != nil {
log.Fatal("Can't render self-test ", err)
log.Fatal("Can't calibrate: ", err)

Check warning on line 99 in mpu9250/main.go

View check run for this annotation

Codecov / codecov/patch

mpu9250/main.go#L99

Added line #L99 was not covered by tests
}

fmt.Printf("Accelerometer Deviation: X: %.2f%%, Y: %.2f%%, Z:%.2f%%\n", st.AccelDeviation.X, st.AccelDeviation.Y, st.AccelDeviation.Z)
Expand Down