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

Fix(core): Semantic Import Versioning for v2 (#921)

This commit is contained in:
Thomas Kohler 2023-05-20 14:25:21 +02:00 committed by GitHub
parent fcdf286f1d
commit 949392d8a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
659 changed files with 2659 additions and 2055 deletions

View File

@ -59,7 +59,7 @@ The basics are as follows:
2. `go get` the upstream repo and set it up as the `upstream` remote and your own repo as the `origin` remote:
`go get gobot.io/x/gobot`
`go get gobot.io/x/gobot/v2`
`cd $GOPATH/src/gobot.io/x/gobot`
`git remote rename origin upstream`
`git remote add origin git@github.com/YOUR_GITHUB_NAME/gobot`

View File

@ -1,6 +1,6 @@
[![Gobot](https://raw.githubusercontent.com/hybridgroup/gobot-site/master/source/images/elements/gobot-logo-small.png)](http://gobot.io/)
[![GoDoc](https://godoc.org/gobot.io/x/gobot?status.svg)](https://godoc.org/gobot.io/x/gobot)
[![GoDoc](https://godoc.org/gobot.io/x/gobot/v2?status.svg)](https://godoc.org/gobot.io/x/gobot/v2)
[![CircleCI Build status](https://circleci.com/gh/hybridgroup/gobot/tree/dev.svg?style=svg)](https://circleci.com/gh/hybridgroup/gobot/tree/dev)
[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/ix29evnbdrhkr7ud/branch/dev?svg=true)](https://ci.appveyor.com/project/deadprogram/gobot/branch/dev)
[![codecov](https://codecov.io/gh/hybridgroup/gobot/branch/dev/graph/badge.svg)](https://codecov.io/gh/hybridgroup/gobot)
@ -17,7 +17,7 @@ Want to run Go directly on microcontrollers? Check out our sister project TinyGo
## Getting Started
Get the Gobot package by running this command: `go get -d -u gobot.io/x/gobot`
Get the Gobot package by running this command: `go get -d -u gobot.io/x/gobot/v2`
## Examples
@ -29,9 +29,9 @@ package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/firmata"
)
func main() {
@ -63,8 +63,8 @@ import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/sphero"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/sphero"
)
func main() {
@ -96,8 +96,8 @@ the various Gobot packages to control hardware with nothing but pure idiomatic G
package main
import (
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/intel-iot/edison"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
"time"
)
@ -127,9 +127,9 @@ import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
"gobot.io/x/gobot/platforms/sphero"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/platforms/sphero"
)
func NewSwarmBot(port string) *gobot.Robot {
@ -329,7 +329,7 @@ More platforms and drivers are coming soon...
Gobot includes a RESTful API to query the status of any robot running within a group, including the connection and
device status, and execute device commands.
To activate the API, import the `gobot.io/x/gobot/api` package and instantiate the `API` like this:
To activate the API, import the `gobot.io/x/gobot/v2/api` package and instantiate the `API` like this:
```go
master := gobot.NewMaster()

View File

@ -10,8 +10,8 @@ import (
"strings"
"github.com/bmizerany/pat"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api/robeaux"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api/robeaux"
)
// API represents an API server

View File

@ -11,8 +11,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
func initTestAPI() *API {

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func TestBasicAuth(t *testing.T) {

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func TestCORSIsOriginAllowed(t *testing.T) {

View File

@ -3,35 +3,35 @@ Package api provides a webserver to interact with your Gobot program over the ne
Example:
package main
package main
import (
"fmt"
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
)
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
)
func main() {
gbot := gobot.NewMaster()
func main() {
gbot := gobot.NewMaster()
// Starts the API server on default port 3000
api.NewAPI(gbot).Start()
// Starts the API server on default port 3000
api.NewAPI(gbot).Start()
// Accessible via http://localhost:3000/api/commands/say_hello
gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
return "Master says hello!"
})
// Accessible via http://localhost:3000/api/commands/say_hello
gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
return "Master says hello!"
})
hello := gbot.AddRobot(gobot.NewRobot("Eve"))
hello := gbot.AddRobot(gobot.NewRobot("Eve"))
// Accessible via http://localhost:3000/api/robots/Eve/commands/say_hello
hello.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
return fmt.Sprintf("%v says hello!", hello.Name)
})
// Accessible via http://localhost:3000/api/robots/Eve/commands/say_hello
hello.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
return fmt.Sprintf("%v says hello!", hello.Name)
})
gbot.Start()
}
gbot.Start()
}
It follows Common Protocol for Programming Physical Input and Output (CPPP-IO) spec:
https://gobot.io/x/cppp-io

View File

@ -3,7 +3,7 @@ package api
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
type NullReadWriteCloser struct{}

View File

@ -189,7 +189,7 @@ func driver() string {
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
const Hello string = "hello"
@ -274,7 +274,7 @@ import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
func main() {
@ -313,8 +313,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*{{.UpperName}}Driver)(nil)
@ -368,8 +368,8 @@ func adaptorTest() string {
import (
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Adaptor = (*{{.UpperName}}Adaptor)(nil)
@ -398,7 +398,7 @@ Gobot (http://gobot.io/) is a framework for robotics and physical computing usin
This repository contains the Gobot adaptor and driver for {{.Package}}.
For more information about Gobot, check out the github repo at
https://gobot.io/x/gobot
https://gobot.io/x/gobot/v2
## Installing
` + "```bash\ngo get path/to/repo/{{.Package}}\n```" + `

View File

@ -4,14 +4,14 @@ import (
"os"
"github.com/urfave/cli"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
func main() {
app := cli.NewApp()
app.Name = "gobot"
app.Author = "The Gobot team"
app.Email = "https://gobot.io/x/gobot"
app.Email = "https://gobot.io/x/gobot/v2"
app.Version = gobot.Version()
app.Usage = "Command Line Utility for generating new Gobot adaptors, drivers, and platforms"
app.Commands = []cli.Command{

View File

@ -3,7 +3,7 @@ package gobot
import (
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func TestCommaner(t *testing.T) {

146
doc.go
View File

@ -5,129 +5,129 @@ Package gobot is the primary entrypoint for Gobot (http://gobot.io), a framework
It provides a simple, yet powerful way to create solutions that incorporate multiple, different hardware devices at the same time.
Classic Gobot
# Classic Gobot
Here is a "Classic Gobot" program that blinks an LED using an Arduino:
package main
import (
"time"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "13")
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "13")
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
)
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
)
robot.Start()
robot.Start()
}
Metal Gobot
# Metal Gobot
You can also use Metal Gobot and pick and choose from the various Gobot packages to control hardware with nothing but pure idiomatic Golang code. For example:
package main
import (
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/intel-iot/edison"
"time"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
"time"
)
func main() {
e := edison.NewAdaptor()
e.Connect()
e := edison.NewAdaptor()
e.Connect()
led := gpio.NewLedDriver(e, "13")
led.Start()
led := gpio.NewLedDriver(e, "13")
led.Start()
for {
led.Toggle()
time.Sleep(1000 * time.Millisecond)
}
for {
led.Toggle()
time.Sleep(1000 * time.Millisecond)
}
}
Master Gobot
# Master Gobot
Finally, you can use Master Gobot to add the complete Gobot API or control swarms of Robots:
package main
import (
"fmt"
"time"
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
"gobot.io/x/gobot/platforms/sphero"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/platforms/sphero"
)
func NewSwarmBot(port string) *gobot.Robot {
spheroAdaptor := sphero.NewAdaptor(port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)
spheroAdaptor := sphero.NewAdaptor(port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)
work := func() {
spheroDriver.Stop()
work := func() {
spheroDriver.Stop()
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Println("Collision Detected!")
})
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
robot := gobot.NewRobot("sphero",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
return robot
return robot
}
func main() {
master := gobot.NewMaster()
api.NewAPI(master).Start()
master := gobot.NewMaster()
api.NewAPI(master).Start()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
for _, port := range spheros {
master.AddRobot(NewSwarmBot(port))
}
for _, port := range spheros {
master.AddRobot(NewSwarmBot(port))
}
master.Start()
master.Start()
}
Copyright (c) 2013-2018 The Hybrid Group. Licensed under the Apache 2.0 license.
*/
package gobot // import "gobot.io/x/gobot"
package gobot // import "gobot.io/x/gobot/v2"

View File

@ -1,22 +1,27 @@
# AIO
This package provides drivers for [Analog Input/Output (AIO)](https://en.wikipedia.org/wiki/Analog-to-digital_converter) devices. It is normally used by connecting an adaptor such as [firmata](https://gobot.io/x/gobot/platforms/firmata) that supports the needed interfaces for analog devices.
This package provides drivers for [Analog Input/Output (AIO)](https://en.wikipedia.org/wiki/Analog-to-digital_converter)
devices. It is normally used by connecting an adaptor such as [BeagleBone](https://gobot.io/documentation/platforms/beaglebone/)
that supports the needed interfaces for analog devices.
## Getting Started
## Installing
```
go get -d -u gobot.io/x/gobot/...
```sh
go get -d -u gobot.io/x/gobot/v2/...
```
## Hardware Support
Gobot has a extensible system for connecting to hardware devices. The following AIO devices are currently supported:
- Analog Sensor
- Analog Actuator
- Grove Light Sensor
- Grove Rotary Dial
- Grove Sound Sensor
- Grove Temperature Sensor
- Temperature Sensor (supports linear and NTC thermistor in normal and inverse mode)
- Analog Sensor
- Analog Actuator
- Grove Light Sensor
- Grove Rotary Dial
- Grove Sound Sensor
- Grove Temperature Sensor
- Temperature Sensor (supports linear and NTC thermistor in normal and inverse mode)
More drivers are coming soon...

View File

@ -3,7 +3,7 @@ package aio
import (
"strconv"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// AnalogActuatorDriver represents an analog actuator
@ -23,8 +23,9 @@ type AnalogActuatorDriver struct {
// The default scaling is 1:1. An adjustable linear scaler is provided by the driver.
//
// Adds the following API Commands:
// "Write" - See AnalogActuator.Write
// "RawWrite" - See AnalogActuator.RawWrite
//
// "Write" - See AnalogActuator.Write
// "RawWrite" - See AnalogActuator.RawWrite
func NewAnalogActuatorDriver(a AnalogWriter, pin string) *AnalogActuatorDriver {
d := &AnalogActuatorDriver{
name: gobot.DefaultName("AnalogActuator"),

View File

@ -4,7 +4,7 @@ import (
"strings"
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func TestAnalogActuatorDriver(t *testing.T) {

View File

@ -3,7 +3,7 @@ package aio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// AnalogSensorDriver represents an Analog Sensor
@ -26,11 +26,13 @@ type AnalogSensorDriver struct {
// The default scaling is 1:1. An adjustable linear scaler is provided by the driver.
//
// Optionally accepts:
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// Adds the following API Commands:
// "Read" - See AnalogDriverSensor.Read
// "ReadRaw" - See AnalogDriverSensor.ReadRaw
//
// "Read" - See AnalogDriverSensor.Read
// "ReadRaw" - See AnalogDriverSensor.ReadRaw
func NewAnalogSensorDriver(a AnalogReader, pin string, v ...time.Duration) *AnalogSensorDriver {
d := &AnalogSensorDriver{
name: gobot.DefaultName("AnalogSensor"),
@ -66,6 +68,7 @@ func NewAnalogSensorDriver(a AnalogReader, pin string, v ...time.Duration) *Anal
// Start starts the AnalogSensorDriver and reads the sensor at the given interval.
// Emits the Events:
//
// Data int - Event is emitted on change and represents the current raw reading from the sensor.
// Value float64 - Event is emitted on change and represents the current reading from the sensor.
// Error error - Event is emitted on error reading from the sensor.

View File

@ -6,8 +6,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*AnalogSensorDriver)(nil)

View File

@ -3,9 +3,9 @@ Package aio provides Gobot drivers for Analog Input/Output devices.
Installing:
go get -d -u gobot.io/x/gobot
go get -d -u gobot.io/x/gobot/v2
For further information refer to aio README:
https://github.com/hybridgroup/gobot/blob/master/platforms/aio/README.md
*/
package aio // import "gobot.io/x/gobot/drivers/aio"
package aio // import "gobot.io/x/gobot/v2/drivers/aio"

View File

@ -7,8 +7,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
type DriverAndPinner interface {

View File

@ -3,7 +3,7 @@ package aio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
var _ gobot.Driver = (*GroveTemperatureSensorDriver)(nil)
@ -18,11 +18,13 @@ type GroveTemperatureSensorDriver struct {
// 10 Milliseconds given an AnalogReader and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the sensor is polled for new information (given 0 switch the polling off)
//
// time.Duration: Interval at which the sensor is polled for new information (given 0 switch the polling off)
//
// Adds the following API Commands:
// "Read" - See AnalogDriverSensor.Read
// "ReadValue" - See AnalogDriverSensor.ReadValue
//
// "Read" - See AnalogDriverSensor.Read
// "ReadValue" - See AnalogDriverSensor.ReadValue
func NewGroveTemperatureSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveTemperatureSensorDriver {
t := NewTemperatureSensorDriver(a, pin, v...)
ntc := TemperatureSensorNtcConf{TC0: 25, R0: 10000.0, B: 3975} //Ohm, R25=10k

View File

@ -6,8 +6,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*GroveTemperatureSensorDriver)(nil)

View File

@ -4,7 +4,7 @@ import (
"math"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
const kelvinOffset = 273.15
@ -31,11 +31,13 @@ type TemperatureSensorDriver struct {
// Linear scaling and NTC scaling is supported.
//
// Optionally accepts:
// time.Duration: Interval at which the sensor is polled for new information (given 0 switch the polling off)
//
// time.Duration: Interval at which the sensor is polled for new information (given 0 switch the polling off)
//
// Adds the following API Commands:
// "Read" - See AnalogDriverSensor.Read
// "ReadValue" - See AnalogDriverSensor.ReadValue
//
// "Read" - See AnalogDriverSensor.Read
// "ReadValue" - See AnalogDriverSensor.ReadValue
func NewTemperatureSensorDriver(a AnalogReader, pin string, v ...time.Duration) *TemperatureSensorDriver {
ad := NewAnalogSensorDriver(a, pin, v...)

View File

@ -7,7 +7,7 @@ import (
"testing"
"time"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func TestTemperatureSensorDriver(t *testing.T) {

View File

@ -3,7 +3,7 @@ package mfrc522
import (
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
type busConnMock struct {

View File

@ -1,33 +1,38 @@
# GPIO
This package provides drivers for [General Purpose Input/Output (GPIO)](https://en.wikipedia.org/wiki/General_Purpose_Input/Output) devices. It is normally used by connecting an adaptor such as [firmata](https://gobot.io/x/gobot/platforms/firmata) that supports the needed interfaces for GPIO devices.
This package provides drivers for [General Purpose Input/Output (GPIO)](https://en.wikipedia.org/wiki/General_Purpose_Input/Output)
devices. It is normally used by connecting an adaptor such as [Raspberry Pi](https://gobot.io/documentation/platforms/raspi/)
that supports the needed interfaces for GPIO devices.
## Getting Started
## Installing
```
go get -d -u gobot.io/x/gobot/...
```sh
go get -d -u gobot.io/x/gobot/v2/...
```
## Hardware Support
Gobot has a extensible system for connecting to hardware devices. The following GPIO devices are currently supported:
- Button
- Buzzer
- Direct Pin
- Grove Button
- Grove Buzzer
- Grove LED
- Grove Magnetic Switch
- Grove Relay
- Grove Touch Sensor
- LED
- Makey Button
- Motor
- Proximity Infra Red (PIR) Motion Sensor
- Relay
- RGB LED
- Servo
- Stepper Motor
- TM1638 LED Controller
- Button
- Buzzer
- Direct Pin
- Grove Button
- Grove Buzzer
- Grove LED
- Grove Magnetic Switch
- Grove Relay
- Grove Touch Sensor
- LED
- Makey Button
- Motor
- Proximity Infra Red (PIR) Motion Sensor
- Relay
- RGB LED
- Servo
- Stepper Motor
- TM1638 LED Controller
More drivers are coming soon...

View File

@ -3,7 +3,7 @@ package gpio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// Commands of the driver

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*AIP1640Driver)(nil)

View File

@ -3,7 +3,7 @@ package gpio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// ButtonDriver Represents a digital Button
@ -22,7 +22,8 @@ type ButtonDriver struct {
// 10 Milliseconds given a DigitalReader and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the ButtonDriver is polled for new information
//
// time.Duration: Interval at which the ButtonDriver is polled for new information
func NewButtonDriver(a DigitalReader, pin string, v ...time.Duration) *ButtonDriver {
b := &ButtonDriver{
name: gobot.DefaultName("Button"),
@ -49,7 +50,8 @@ func NewButtonDriver(a DigitalReader, pin string, v ...time.Duration) *ButtonDri
// Start starts the ButtonDriver and polls the state of the button at the given interval.
//
// Emits the Events:
// Push int - On button push
//
// Push int - On button push
// Release int - On button release
// Error error - On button error
func (b *ButtonDriver) Start() (err error) {

View File

@ -6,8 +6,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*ButtonDriver)(nil)

View File

@ -3,7 +3,7 @@ package gpio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// Some useful divider

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*BuzzerDriver)(nil)

View File

@ -3,7 +3,7 @@ package gpio
import (
"strconv"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// DirectPinDriver represents a GPIO pin
@ -17,10 +17,11 @@ type DirectPinDriver struct {
// NewDirectPinDriver return a new DirectPinDriver given a Connection and pin.
//
// Adds the following API Commands:
// "DigitalRead" - See DirectPinDriver.DigitalRead
// "DigitalWrite" - See DirectPinDriver.DigitalWrite
// "PwmWrite" - See DirectPinDriver.PwmWrite
// "ServoWrite" - See DirectPinDriver.ServoWrite
//
// "DigitalRead" - See DirectPinDriver.DigitalRead
// "DigitalWrite" - See DirectPinDriver.DigitalWrite
// "PwmWrite" - See DirectPinDriver.PwmWrite
// "ServoWrite" - See DirectPinDriver.ServoWrite
func NewDirectPinDriver(a gobot.Connection, pin string) *DirectPinDriver {
d := &DirectPinDriver{
name: gobot.DefaultName("DirectPin"),

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*DirectPinDriver)(nil)

View File

@ -3,9 +3,9 @@ Package gpio provides Gobot drivers for General Purpose Input/Output devices.
Installing:
go get -d -u gobot.io/x/gobot
go get -d -u gobot.io/x/gobot/v2
For further information refer to gpio README:
https://github.com/hybridgroup/gobot/blob/master/platforms/gpio/README.md
*/
package gpio // import "gobot.io/x/gobot/drivers/gpio"
package gpio // import "gobot.io/x/gobot/v2/drivers/gpio"

View File

@ -5,7 +5,7 @@ import (
"strconv"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// EasyDriver object

View File

@ -1,10 +1,11 @@
package gpio
import (
"gobot.io/x/gobot/gobottest"
"strings"
"testing"
"time"
"gobot.io/x/gobot/v2/gobottest"
)
const (
@ -183,4 +184,3 @@ func TestEasyDriverDisable(t *testing.T) {
gobottest.Assert(t, d.IsEnabled(), false)
gobottest.Assert(t, d.IsMoving(), false)
}

View File

@ -7,8 +7,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
type DriverAndPinner interface {

View File

@ -6,7 +6,7 @@ import (
"sync"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// Commands for the driver

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*HD44780Driver)(nil)

View File

@ -1,6 +1,6 @@
package gpio
import "gobot.io/x/gobot"
import "gobot.io/x/gobot/v2"
// LedDriver represents a digital Led
type LedDriver struct {
@ -14,6 +14,7 @@ type LedDriver struct {
// NewLedDriver return a new LedDriver given a DigitalWriter and pin.
//
// Adds the following API Commands:
//
// "Brightness" - See LedDriver.Brightness
// "Toggle" - See LedDriver.Toggle
// "On" - See LedDriver.On

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*LedDriver)(nil)

View File

@ -3,7 +3,7 @@ package gpio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// MakeyButtonDriver Represents a Makey Button
@ -21,7 +21,8 @@ type MakeyButtonDriver struct {
// 10 Milliseconds given a DigitalReader and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the ButtonDriver is polled for new information
//
// time.Duration: Interval at which the ButtonDriver is polled for new information
func NewMakeyButtonDriver(a DigitalReader, pin string, v ...time.Duration) *MakeyButtonDriver {
m := &MakeyButtonDriver{
name: gobot.DefaultName("MakeyButton"),
@ -59,7 +60,8 @@ func (b *MakeyButtonDriver) Connection() gobot.Connection { return b.connection.
// Start starts the MakeyButtonDriver and polls the state of the button at the given interval.
//
// Emits the Events:
// Push int - On button push
//
// Push int - On button push
// Release int - On button release
// Error error - On button error
func (b *MakeyButtonDriver) Start() (err error) {

View File

@ -5,8 +5,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*MakeyButtonDriver)(nil)

View File

@ -1,7 +1,7 @@
package gpio
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// Access and command constants for the driver

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*MAX7219Driver)(nil)

View File

@ -1,7 +1,7 @@
package gpio
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// MotorDriver Represents a Motor

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*MotorDriver)(nil)

View File

@ -3,7 +3,7 @@ package gpio
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// PIRMotionDriver represents a digital Proximity Infra Red (PIR) motion detecter
@ -21,7 +21,8 @@ type PIRMotionDriver struct {
// 10 Milliseconds given a DigitalReader and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the PIRMotionDriver is polled for new information
//
// time.Duration: Interval at which the PIRMotionDriver is polled for new information
func NewPIRMotionDriver(a DigitalReader, pin string, v ...time.Duration) *PIRMotionDriver {
b := &PIRMotionDriver{
name: gobot.DefaultName("PIRMotion"),
@ -47,7 +48,8 @@ func NewPIRMotionDriver(a DigitalReader, pin string, v ...time.Duration) *PIRMot
// Start starts the PIRMotionDriver and polls the state of the sensor at the given interval.
//
// Emits the Events:
// MotionDetected - On motion detected
//
// MotionDetected - On motion detected
// MotionStopped int - On motion stopped
// Error error - On button error
//

View File

@ -6,8 +6,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*PIRMotionDriver)(nil)

View File

@ -1,6 +1,6 @@
package gpio
import "gobot.io/x/gobot"
import "gobot.io/x/gobot/v2"
// RelayDriver represents a digital relay
type RelayDriver struct {
@ -15,6 +15,7 @@ type RelayDriver struct {
// NewRelayDriver return a new RelayDriver given a DigitalWriter and pin.
//
// Adds the following API Commands:
//
// "Toggle" - See RelayDriver.Toggle
// "On" - See RelayDriver.On
// "Off" - See RelayDriver.Off

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*RelayDriver)(nil)

View File

@ -1,6 +1,6 @@
package gpio
import "gobot.io/x/gobot"
import "gobot.io/x/gobot/v2"
// RgbLedDriver represents a digital RGB Led
type RgbLedDriver struct {
@ -20,6 +20,7 @@ type RgbLedDriver struct {
// 3 pins: redPin, greenPin, and bluePin
//
// Adds the following API Commands:
//
// "SetRGB" - See RgbLedDriver.SetRGB
// "Toggle" - See RgbLedDriver.Toggle
// "On" - See RgbLedDriver.On
@ -70,7 +71,9 @@ func (l *RgbLedDriver) Name() string { return l.name }
func (l *RgbLedDriver) SetName(n string) { l.name = n }
// Pin returns the RgbLedDrivers pins
func (l *RgbLedDriver) Pin() string { return "r=" + l.pinRed + ", g=" + l.pinGreen + ", b=" + l.pinBlue }
func (l *RgbLedDriver) Pin() string {
return "r=" + l.pinRed + ", g=" + l.pinGreen + ", b=" + l.pinBlue
}
// RedPin returns the RgbLedDrivers redPin
func (l *RgbLedDriver) RedPin() string { return l.pinRed }

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*RgbLedDriver)(nil)

View File

@ -1,6 +1,6 @@
package gpio
import "gobot.io/x/gobot"
import "gobot.io/x/gobot/v2"
// ServoDriver Represents a Servo
type ServoDriver struct {
@ -14,7 +14,8 @@ type ServoDriver struct {
// NewServoDriver returns a new ServoDriver given a ServoWriter and pin.
//
// Adds the following API Commands:
// "Move" - See ServoDriver.Move
//
// "Move" - See ServoDriver.Move
// "Min" - See ServoDriver.Min
// "Center" - See ServoDriver.Center
// "Max" - See ServoDriver.Max

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*ServoDriver)(nil)

View File

@ -8,7 +8,7 @@ import (
"sync"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
type phase [][4]byte

View File

@ -6,7 +6,7 @@ import (
"testing"
"time"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
const (

View File

@ -5,7 +5,7 @@ import (
"strings"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// Colors of the display

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*TM1638Driver)(nil)

View File

@ -1,15 +1,19 @@
# I2C
This package provides drivers for [i2c](https://en.wikipedia.org/wiki/I%C2%B2C)devices. It must be used along with an adaptor such as [firmata](https://gobot.io/x/gobot/platforms/firmata) that supports the needed interfaces for i2c devices.
This package provides drivers for [i2c](https://en.wikipedia.org/wiki/I%C2%B2C)devices. It must be used along with an
adaptor such as [Tinker Board](https://gobot.io/documentation/platforms/tinkerboard/) that supports the needed
interfaces for i2c devices.
## Getting Started
## Installing
```
go get -d -u gobot.io/x/gobot/...
```sh
go get -d -u gobot.io/x/gobot/v2/...
```
## Hardware Support
Gobot has a extensible system for connecting to hardware devices. The following i2c devices are currently supported:
- Adafruit 2x16 RGB-LCD with 5 keys
@ -54,7 +58,8 @@ More drivers are coming soon...
## Using A Different Bus or Address
You can set a different I2C address or I2C bus than the default when initializing your I2C drivers by using optional parameters. Here is an example:
You can set a different I2C address or I2C bus than the default when initializing your I2C drivers by using optional
parameters. Here is an example:
```go
blinkm := i2c.NewBlinkMDriver(e, i2c.WithBus(0), i2c.WithAddress(0x09))

View File

@ -6,8 +6,8 @@ import (
"strconv"
"strings"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
)
const adafruit1109Debug = false

View File

@ -6,8 +6,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*Adafruit1109Driver)(nil)

View File

@ -6,7 +6,7 @@ import (
"math"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// AdafruitDirection declares a type for specification of the motor direction
@ -97,12 +97,13 @@ const (
// NewAdafruitMotorHatDriver initializes the internal DCMotor and StepperMotor types.
// Again the Adafruit Motor Hat supports up to four DC motors and up to two stepper motors.
// Params:
// conn Connector - the Adaptor to use with this Driver
//
// conn Connector - the Adaptor to use with this Driver
//
// Optional params:
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
//
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
func NewAdafruitMotorHatDriver(conn Connector, options ...func(Config)) *AdafruitMotorHatDriver {
var dc []adaFruitDCMotor
var st []adaFruitStepperMotor

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation implements the gobot.Driver interface

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func initTestADS1015DriverWithStubbedAdaptor() (*ADS1x15Driver, *i2cTestAdaptor) {

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func initTestADS1115DriverWithStubbedAdaptor() (*ADS1x15Driver, *i2cTestAdaptor) {

View File

@ -4,9 +4,9 @@ import (
"errors"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/aio"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -7,8 +7,8 @@ import (
"bytes"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -39,8 +39,8 @@ type bmeHumidityCalibrationCoefficients struct {
// It implements all of the same functions as the BMP280Driver, but also
// adds the Humidity() function by reading the BME280's humidity sensor.
// For details on the BMP280Driver please see:
// https://godoc.org/gobot.io/x/gobot/drivers/i2c#BMP280Driver
//
// https://godoc.org/gobot.io/x/gobot/v2/drivers/i2c#BMP280Driver
type BME280Driver struct {
*BMP280Driver
humCalCoeffs *bmeHumidityCalibrationCoefficients
@ -49,12 +49,13 @@ type BME280Driver struct {
// NewBME280Driver creates a new driver with specified i2c interface.
// Params:
// conn Connector - the Adaptor to use with this Driver
//
// conn Connector - the Adaptor to use with this Driver
//
// Optional params:
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
//
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
func NewBME280Driver(c Connector, options ...func(Config)) *BME280Driver {
d := &BME280Driver{
BMP280Driver: NewBMP280Driver(c),

View File

@ -6,8 +6,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -8,8 +8,8 @@ import (
"testing"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -6,8 +6,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -7,8 +7,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -3,9 +3,9 @@ Package i2c provides Gobot drivers for i2c devices.
Installing:
go get -d -u gobot.io/x/gobot
go get -d -u gobot.io/x/gobot/v2
For further information refer to i2c README:
https://github.com/hybridgroup/gobot/blob/master/drivers/i2c/README.md
*/
package i2c // import "gobot.io/x/gobot/drivers/i2c"
package i2c // import "gobot.io/x/gobot/v2/drivers/i2c"

View File

@ -7,8 +7,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*GenericDriver)(nil)

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*GroveLcdDriver)(nil)

View File

@ -5,10 +5,10 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/aio"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver
@ -70,67 +70,67 @@ func TestGrovePiSomeRead(t *testing.T) {
"DigitalRead": {
usedPin: 2,
wantWritten: []uint8{commandSetPinMode, 2, 0, 0, commandReadDigital, 2, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{commandReadDigital, 3}},
simResponse: [][]uint8{{0}, {commandReadDigital, 3}},
wantCallsRead: 2,
wantResult: 3,
},
"AnalogRead": {
usedPin: 3,
wantWritten: []uint8{commandSetPinMode, 3, 0, 0, commandReadAnalog, 3, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{commandReadAnalog, 4, 5}},
simResponse: [][]uint8{{0}, {commandReadAnalog, 4, 5}},
wantResult: 1029,
},
"UltrasonicRead": {
usedPin: 4,
wantWritten: []uint8{commandSetPinMode, 4, 0, 0, commandReadUltrasonic, 4, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{commandReadUltrasonic, 5, 6}},
simResponse: [][]uint8{{0}, {commandReadUltrasonic, 5, 6}},
wantResult: 1281,
},
"FirmwareVersionRead": {
wantWritten: []uint8{commandReadFirmwareVersion, 0, 0, 0},
simResponse: [][]uint8{[]uint8{commandReadFirmwareVersion, 7, 8, 9}},
simResponse: [][]uint8{{commandReadFirmwareVersion, 7, 8, 9}},
wantResultString: "7.8.9",
},
"DHTRead": {
usedPin: 5,
wantWritten: []uint8{commandSetPinMode, 5, 0, 0, commandReadDHT, 5, 1, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{commandReadDHT, 164, 112, 69, 193, 20, 174, 54, 66}},
simResponse: [][]uint8{{0}, {commandReadDHT, 164, 112, 69, 193, 20, 174, 54, 66}},
wantResultF1: -12.34,
wantResultF2: 45.67,
},
"DigitalRead_error_wrong_return_cmd": {
usedPin: 15,
wantWritten: []uint8{commandSetPinMode, 15, 0, 0, commandReadDigital, 15, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{0, 2}},
simResponse: [][]uint8{{0}, {0, 2}},
wantErr: fmt.Errorf("answer (0) was not for command (1)"),
},
"AnalogRead_error_wrong_return_cmd": {
usedPin: 16,
wantWritten: []uint8{commandSetPinMode, 16, 0, 0, commandReadAnalog, 16, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{0, 3, 4}},
simResponse: [][]uint8{{0}, {0, 3, 4}},
wantErr: fmt.Errorf("answer (0) was not for command (3)"),
},
"UltrasonicRead_error_wrong_return_cmd": {
usedPin: 17,
wantWritten: []uint8{commandSetPinMode, 17, 0, 0, commandReadUltrasonic, 17, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{0, 5, 6}},
simResponse: [][]uint8{{0}, {0, 5, 6}},
wantErr: fmt.Errorf("answer (0) was not for command (7)"),
},
"FirmwareVersionRead_error_wrong_return_cmd": {
wantWritten: []uint8{commandReadFirmwareVersion, 0, 0, 0},
simResponse: [][]uint8{[]uint8{0, 7, 8, 9}},
simResponse: [][]uint8{{0, 7, 8, 9}},
wantErr: fmt.Errorf("answer (0) was not for command (8)"),
},
"DHTRead_error_wrong_return_cmd": {
usedPin: 18,
wantWritten: []uint8{commandSetPinMode, 18, 0, 0, commandReadDHT, 18, 1, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{0, 164, 112, 69, 193, 20, 174, 54, 66}},
simResponse: [][]uint8{{0}, {0, 164, 112, 69, 193, 20, 174, 54, 66}},
wantErr: fmt.Errorf("answer (0) was not for command (40)"),
},
"DigitalRead_error_wrong_data_count": {
usedPin: 28,
wantWritten: []uint8{commandSetPinMode, 28, 0, 0, commandReadDigital, 28, 0, 0},
simResponse: [][]uint8{[]uint8{0}, []uint8{commandReadDigital, 2, 3}},
simResponse: [][]uint8{{0}, {commandReadDigital, 2, 3}},
wantErr: fmt.Errorf("read count mismatch (3 should be 2)"),
},
}

View File

@ -4,8 +4,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -3,7 +3,7 @@ package i2c
import (
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2/gobottest"
)
func TestNewConfig(t *testing.T) {

View File

@ -3,7 +3,7 @@ package i2c
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
const (

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package i2c
@ -9,9 +10,9 @@ import (
"syscall"
"unsafe"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/system"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
"gobot.io/x/gobot/v2/system"
)
const dev = "/dev/i2c-1"

View File

@ -6,7 +6,7 @@ import (
"strconv"
"sync"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// Config is the interface to set and get I2C device related parameters.

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*Driver)(nil)

View File

@ -7,8 +7,8 @@ import (
"strings"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,7 +5,7 @@ import (
"strconv"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
const (
@ -86,11 +86,12 @@ type JHD1313M1Driver struct {
// NewJHD1313M1Driver creates a new driver with specified i2c interface.
// Params:
// conn Connector - the Adaptor to use with this Driver
//
// conn Connector - the Adaptor to use with this Driver
//
// Optional params:
// i2c.WithBus(int): bus to use with this driver
//
// i2c.WithBus(int): bus to use with this driver
func NewJHD1313M1Driver(a Connector, options ...func(Config)) *JHD1313M1Driver {
j := &JHD1313M1Driver{
name: gobot.DefaultName("JHD1313M1"),

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
var _ gobot.Driver = (*JHD1313M1Driver)(nil)

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -6,8 +6,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,7 +5,7 @@ import (
"log"
"strings"
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
)
// default address for device when a2/a1/a0 pins are all tied to ground
@ -63,19 +63,20 @@ type MCP23017Driver struct {
// NewMCP23017Driver creates a new Gobot Driver to the MCP23017 i2c port expander.
// Params:
// c Connector - the Adaptor to use with this Driver
//
// c Connector - the Adaptor to use with this Driver
//
// Optional params:
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
// i2c.WithMCP23017Bank(int): MCP23017 bank to use with this driver
// i2c.WithMCP23017Mirror(int): MCP23017 mirror to use with this driver
// i2c.WithMCP23017Seqop(int): MCP23017 seqop to use with this driver
// i2c.WithMCP23017Disslw(int): MCP23017 disslw to use with this driver
// i2c.WithMCP23017Haen(int): MCP23017 haen to use with this driver
// i2c.WithMCP23017Odr(int): MCP23017 odr to use with this driver
// i2c.WithMCP23017Intpol(int): MCP23017 intpol to use with this driver
//
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
// i2c.WithMCP23017Bank(int): MCP23017 bank to use with this driver
// i2c.WithMCP23017Mirror(int): MCP23017 mirror to use with this driver
// i2c.WithMCP23017Seqop(int): MCP23017 seqop to use with this driver
// i2c.WithMCP23017Disslw(int): MCP23017 disslw to use with this driver
// i2c.WithMCP23017Haen(int): MCP23017 haen to use with this driver
// i2c.WithMCP23017Odr(int): MCP23017 odr to use with this driver
// i2c.WithMCP23017Intpol(int): MCP23017 intpol to use with this driver
func NewMCP23017Driver(c Connector, options ...func(Config)) *MCP23017Driver {
d := &MCP23017Driver{
Driver: NewDriver(c, "MCP23017", mcp23017DefaultAddress),

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -1,7 +1,7 @@
package i2c
import (
"gobot.io/x/gobot/drivers/common/mfrc522"
"gobot.io/x/gobot/v2/drivers/common/mfrc522"
)
const mfrc522DefaultAddress = 0x00
@ -16,11 +16,13 @@ type MFRC522Driver struct {
// NewMFRC522Driver creates a new Gobot Driver for MFRC522 RFID with i2c connection
//
// Params:
// c Connector - the Adaptor to use with this Driver
//
// c Connector - the Adaptor to use with this Driver
//
// Optional params:
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
//
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
func NewMFRC522Driver(c Connector, options ...func(Config)) *MFRC522Driver {
d := &MFRC522Driver{
Driver: NewDriver(c, "MFRC522", mfrc522DefaultAddress),

View File

@ -6,8 +6,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -1,7 +1,7 @@
package i2c
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/v2"
"bytes"
"encoding/binary"
@ -47,12 +47,13 @@ type MPL115A2Driver struct {
// I2C Pressure/Temperature sensor.
//
// Params:
// c Connector - the Adaptor to use with this Driver
//
// c Connector - the Adaptor to use with this Driver
//
// Optional params:
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
//
// i2c.WithBus(int): bus to use with this driver
// i2c.WithAddress(int): address to use with this driver
func NewMPL115A2Driver(c Connector, options ...func(Config)) *MPL115A2Driver {
d := &MPL115A2Driver{
Driver: NewDriver(c, "MPL115A2", mpl115a2DefaultAddress),

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

View File

@ -5,8 +5,8 @@ import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/gobottest"
)
// this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver

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