mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-09 19:29:27 +08:00
commit
57b31e84c2
8
.github/pull_request_template.md
vendored
8
.github/pull_request_template.md
vendored
@ -4,18 +4,20 @@
|
||||
|
||||
## Manual test
|
||||
|
||||
* OS and Version (Win/Mac/Linux):
|
||||
* Adaptor(s) and/or driver(s):
|
||||
- OS and Version (Win/Mac/Linux):
|
||||
- Adaptor(s) and/or driver(s):
|
||||
...
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] The PR's target branch is 'hybridgroup:dev'
|
||||
- [ ] I have performed a self-review of my own code
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] New and existing unit tests pass locally with my changes (e.g. by run `make test`)
|
||||
- [ ] No linter errors exist locally (e.g. by run `make fmt_check`)
|
||||
- [ ] I have performed a self-review of my own code
|
||||
|
||||
If this is a new driver or adaptor:
|
||||
|
||||
- [ ] I have added the name to the corresponding README.md
|
||||
- [ ] 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`)
|
||||
|
47
.github/workflows/golangci-lint.yml
vendored
Normal file
47
.github/workflows/golangci-lint.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
branches:
|
||||
- dev
|
||||
pull_request:
|
||||
permissions:
|
||||
contents: read
|
||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||
# pull-requests: read
|
||||
jobs:
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.17'
|
||||
cache: false
|
||||
- uses: actions/checkout@v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
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.52.2
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# mostly there is no problem locally, but on server: "could not import C (cgo preprocessing failed) (typecheck)"
|
||||
args: --skip-files platforms/digispark/littleWire.go
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
|
||||
# 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
|
61
.golangci.yml
Normal file
61
.golangci.yml
Normal file
@ -0,0 +1,61 @@
|
||||
run:
|
||||
# Timeout for analysis, e.g. 30s, 5m.
|
||||
# gobot is very expensive, on a machine with heavy load it takes some minutes
|
||||
# for first run or after empty the cache by 'golangci-lint cache clean'
|
||||
# Default: 1m
|
||||
timeout: 5m
|
||||
|
||||
# If set we pass it to "go list -mod={option}". From "go help modules":
|
||||
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
||||
# automatic updating of go.mod described above. Instead, it fails when any changes
|
||||
# to go.mod are needed. This setting is most useful to check that go.mod does
|
||||
# not need updates, such as in a continuous integration and testing system.
|
||||
# If invoked with -mod=vendor, the go command assumes that the vendor
|
||||
# directory holds the correct copies of dependencies and ignores
|
||||
# the dependency descriptions in go.mod.
|
||||
#
|
||||
# Allowed values: readonly|vendor|mod
|
||||
# By default, it isn't set.
|
||||
modules-download-mode: readonly
|
||||
|
||||
# Enables skipping of directories:
|
||||
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||
# Default: true
|
||||
skip-dirs-use-default: false
|
||||
|
||||
# note: examples will be currently omitted by the build tag
|
||||
skip-dirs:
|
||||
- platforms/opencv
|
||||
|
||||
linters:
|
||||
# Enable specific linter
|
||||
# https://golangci-lint.run/usage/linters/#enabled-by-default
|
||||
# note: typecheck can not be disabled, it is used to check code compilation
|
||||
#
|
||||
# TODO: this default linters needs to be disabled to run successfully, we have to fix
|
||||
# all issues step by step to enable at least the default linters
|
||||
disable:
|
||||
- errcheck
|
||||
- ineffassign
|
||||
#- staticcheck
|
||||
- unused
|
||||
|
||||
enable:
|
||||
- nolintlint
|
||||
|
||||
linters-settings:
|
||||
nolintlint:
|
||||
# Enable to require an explanation of nonzero length after each nolint directive.
|
||||
# Default: false
|
||||
require-explanation: true
|
||||
# Enable to require nolint directives to mention the specific linter being suppressed.
|
||||
# Default: false
|
||||
require-specific: true
|
||||
|
||||
revive:
|
||||
rules:
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return
|
||||
# disable this rule, because sometimes it has its justification
|
||||
- name: unexported-return
|
||||
severity: warning
|
||||
disabled: true
|
@ -1,6 +1,7 @@
|
||||
# Contributing to Gobot
|
||||
|
||||
## Target Branch
|
||||
|
||||
**Please open all non-hotfix PRs against the `dev` branch!**
|
||||
|
||||
Gobot follows a ["git flow"](http://nvie.com/posts/a-successful-git-branching-model/)-style model for managing development.
|
||||
@ -19,23 +20,27 @@ This document will guide you through the contribution process.
|
||||
|
||||
What do you want to contribute?
|
||||
|
||||
- I want to otherwise correct or improve the docs or examples
|
||||
- I want to report a bug
|
||||
- I want to add some feature or functionality to an existing hardware platform
|
||||
- I want to add support for a new hardware platform
|
||||
* I want to otherwise correct or improve the docs or examples
|
||||
* I want to report a bug
|
||||
* I want to add some feature or functionality to an existing hardware platform
|
||||
* I want to add support for a new hardware platform
|
||||
|
||||
Descriptions for each of these will eventually be provided below.
|
||||
|
||||
## General Guidelines
|
||||
|
||||
* All active development is in the `dev` branch. New or updated features must be added to the `dev` branch. Hotfixes will be considered on the `master` branch in situations where it does not alter behaviour or features, only fixes a bug.
|
||||
* All active development is in the `dev` branch. New or updated features must be added to the `dev` branch. Hotfixes
|
||||
will be considered on the `master` branch in situations where it does not alter behavior or features, only fixes a bug.
|
||||
* All patches must be provided under the Apache 2.0 License
|
||||
* Please use the -S option in git to "sign off" that the commit is your work and you are providing it under the Apache 2.0 License
|
||||
* Please use the -S option in git to "sign off" that the commit is your work and you are providing it under the
|
||||
Apache 2.0 License
|
||||
* Submit a Github Pull Request to the appropriate branch and ideally discuss the changes with us in IRC.
|
||||
* We will look at the patch, test it out, and give you feedback.
|
||||
* Avoid doing minor whitespace changes, renamings, etc. along with merged content. These will be done by the maintainers from time to time but they can complicate merges and should be done seperately.
|
||||
* Avoid doing minor whitespace changes, renamings, etc. along with merged content. These will be done by the maintainers
|
||||
from time to time but they can complicate merges and should be done separately.
|
||||
* Take care to maintain the existing coding style.
|
||||
* `golint` and `go fmt` your code.
|
||||
* `golangci-lint` your code, see [instruction for local installation](https://golangci-lint.run/usage/install/#local-installation)
|
||||
* `go fmt` your code (with the go version of go.mod)
|
||||
* Add unit tests for any new or changed functionality.
|
||||
* All pull requests should be "fast forward"
|
||||
* If there are commits after yours use “git rebase -i <new_head_branch>”
|
||||
@ -43,6 +48,7 @@ Descriptions for each of these will eventually be provided below.
|
||||
* For git help see [progit](http://git-scm.com/book) which is an awesome (and free) book on git
|
||||
|
||||
## Creating Pull Requests
|
||||
|
||||
Because Gobot makes use of self-referencing import paths, you will want
|
||||
to implement the local copy of your fork as a remote on your copy of the
|
||||
original Gobot repo. Katrina Owen has [an excellent post on this workflow](https://splice.com/blog/contributing-open-source-git-repositories-go/).
|
||||
@ -53,34 +59,38 @@ 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`
|
||||
`cd $GOPATH/src/gobot.io/x/gobot`
|
||||
`git remote rename origin upstream`
|
||||
`git remote add origin git@github.com/YOUR_GITHUB_NAME/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`
|
||||
|
||||
All import paths should now work fine assuming that you've got the
|
||||
proper branch checked out.
|
||||
All import paths should now work fine assuming that you've got the
|
||||
proper branch checked out.
|
||||
|
||||
3. Get all the needed gobot's dependencies each of them at their needed version. Gobot uses [dep (Dependency management for Go)](https://golang.github.io/dep/) to manage the project's dependencies. To get all the correct dependencies:
|
||||
3. Get all the needed gobot's dependencies each of them at their needed version. Gobot uses
|
||||
[dep (Dependency management for Go)](https://golang.github.io/dep/) to manage the project's dependencies. To get all
|
||||
the correct dependencies:
|
||||
|
||||
* Install dep tool. Follow the dep [installation](https://golang.github.io/dep/docs/installation.html) instructions in case you don't have it already installed.
|
||||
* `cd $GOPATH/src/gobot.io/x/gobot`
|
||||
* `dep ensure` will fetch all the dependencies at their needed version.
|
||||
* Install dep tool. Follow the dep [installation](https://golang.github.io/dep/docs/installation.html) instructions in
|
||||
case you don't have it already installed.
|
||||
* `cd $GOPATH/src/gobot.io/x/gobot`
|
||||
* `dep ensure` will fetch all the dependencies at their needed version.
|
||||
|
||||
## Landing Pull Requests
|
||||
|
||||
(This is for committers only. If you are unsure whether you are a committer, you are not.)
|
||||
|
||||
1. Set the contributor's fork as an upstream on your checkout
|
||||
|
||||
`git remote add contrib1 https://github.com/contrib1/gobot`
|
||||
`git remote add contrib1 https://github.com/contrib1/gobot`
|
||||
|
||||
2. Fetch the contributor's repo
|
||||
|
||||
`git fetch contrib1`
|
||||
`git fetch contrib1`
|
||||
|
||||
3. Checkout a copy of the PR branch
|
||||
|
||||
`git checkout pr-1234 --track contrib1/branch-for-pr-1234`
|
||||
`git checkout pr-1234 --track contrib1/branch-for-pr-1234`
|
||||
|
||||
4. Review the PR as normal
|
||||
|
||||
@ -104,7 +114,8 @@ By making a contribution to this project, I certify that:
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
Gobot is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. [You can read about it here](CODE_OF_CONDUCT.md).
|
||||
Gobot is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
|
||||
[You can read about it here](CODE_OF_CONDUCT.md).
|
||||
|
||||
## Origins
|
||||
|
||||
|
8
Makefile
8
Makefile
@ -2,10 +2,12 @@
|
||||
ALL_EXAMPLES := $(shell grep -l -r --include "*.go" 'build example' ./)
|
||||
# prevent examples with gocv (opencv) dependencies
|
||||
EXAMPLES_NO_GOCV := $(shell grep -L 'gocv' $(ALL_EXAMPLES))
|
||||
# prevent examples with joystick (sdl2) dependencies
|
||||
EXAMPLES_NO_JOYSTICK := $(shell grep -L 'joystick' $(ALL_EXAMPLES))
|
||||
# prevent examples with joystick (sdl2) and gocv (opencv) dependencies
|
||||
EXAMPLES_NO_GOCV_JOYSTICK := $(shell grep -L 'joystick' $$(grep -L 'gocv' $(EXAMPLES_NO_GOCV)))
|
||||
# used examples
|
||||
EXAMPLES := $(EXAMPLES_NO_GOCV)
|
||||
EXAMPLES := $(EXAMPLES_NO_GOCV_JOYSTICK)
|
||||
|
||||
.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check $(EXAMPLES)
|
||||
|
||||
@ -54,8 +56,8 @@ version_check:
|
||||
|
||||
# Check for bad code style and other issues
|
||||
fmt_check:
|
||||
gofmt -l ./
|
||||
go vet ./...
|
||||
gofmt -l ./
|
||||
golangci-lint run -v
|
||||
|
||||
# Fix bad code style (will only be executed, on version match)
|
||||
fmt_fix: version_check
|
||||
|
26
README.md
26
README.md
@ -1,6 +1,6 @@
|
||||
[](http://gobot.io/)
|
||||
|
||||
[](https://godoc.org/gobot.io/x/gobot)
|
||||
[](https://godoc.org/gobot.io/x/gobot/v2)
|
||||
[](https://circleci.com/gh/hybridgroup/gobot/tree/dev)
|
||||
[](https://ci.appveyor.com/project/deadprogram/gobot/branch/dev)
|
||||
[](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()
|
||||
|
10
api/api.go
10
api/api.go
@ -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
|
||||
@ -109,7 +109,6 @@ func (a *API) Start() {
|
||||
|
||||
// StartWithoutDefaults initializes the api without setting up the default routes.
|
||||
// Good for custom web interfaces.
|
||||
//
|
||||
func (a *API) StartWithoutDefaults() {
|
||||
a.start(a)
|
||||
}
|
||||
@ -117,7 +116,6 @@ func (a *API) StartWithoutDefaults() {
|
||||
// AddC3PIORoutes adds all of the standard C3PIO routes to the API.
|
||||
// For more information, please see:
|
||||
// http://cppp.io/
|
||||
//
|
||||
func (a *API) AddC3PIORoutes() {
|
||||
mcpCommandRoute := "/api/commands/:command"
|
||||
robotDeviceCommandRoute := "/api/robots/:robot/devices/:device/commands/:command"
|
||||
@ -250,10 +248,8 @@ func (a *API) robotDevice(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) {
|
||||
f, _ := res.(http.Flusher)
|
||||
c, _ := res.(http.CloseNotifier)
|
||||
|
||||
dataChan := make(chan string)
|
||||
closer := c.CloseNotify()
|
||||
|
||||
res.Header().Set("Content-Type", "text/event-stream")
|
||||
res.Header().Set("Cache-Control", "no-cache")
|
||||
@ -275,7 +271,7 @@ func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) {
|
||||
case data := <-dataChan:
|
||||
fmt.Fprintf(res, "data: %v\n\n", data)
|
||||
f.Flush()
|
||||
case <-closer:
|
||||
case <-req.Context().Done():
|
||||
log.Println("Closing connection")
|
||||
return
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -81,7 +81,7 @@ func TestIndex(t *testing.T) {
|
||||
a.ServeHTTP(response, request)
|
||||
|
||||
gobottest.Assert(t, http.StatusMovedPermanently, response.Code)
|
||||
gobottest.Assert(t, "/index.html", response.HeaderMap["Location"][0])
|
||||
gobottest.Assert(t, "/index.html", response.Header()["Location"][0])
|
||||
}
|
||||
|
||||
func TestMcp(t *testing.T) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
42
api/doc.go
42
api/doc.go
@ -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
|
||||
|
@ -3,7 +3,7 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
type NullReadWriteCloser struct{}
|
||||
|
@ -30,7 +30,7 @@ func Generate() cli.Command {
|
||||
valid = true
|
||||
}
|
||||
}
|
||||
if valid == false {
|
||||
if !valid {
|
||||
fmt.Println("Invalid/no subcommand supplied.")
|
||||
fmt.Println("Usage:")
|
||||
fmt.Println(" gobot generate adaptor <name> [package] # generate a new Gobot adaptor")
|
||||
@ -102,7 +102,7 @@ func generate(c config, file string, tmpl string) error {
|
||||
fmt.Println("Creating", fileLocation)
|
||||
|
||||
f, err := os.Create(fileLocation)
|
||||
defer f.Close()
|
||||
defer f.Close() //nolint:staticcheck // for historical reasons
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -149,11 +149,11 @@ func generatePlatform(c config) error {
|
||||
|
||||
c.dir = dir
|
||||
|
||||
if exp, err := ioutil.ReadFile(exampleDir + "/main.go"); err != nil {
|
||||
exp, err := ioutil.ReadFile(exampleDir + "/main.go")
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
c.Example = string(exp)
|
||||
}
|
||||
c.Example = string(exp)
|
||||
|
||||
return generate(c, "README.md", readme())
|
||||
}
|
||||
@ -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```" + `
|
||||
|
@ -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{
|
||||
|
@ -22,10 +22,9 @@ func NewCommander() Commander {
|
||||
}
|
||||
}
|
||||
|
||||
// Command returns the command interface whene passed a valid command name
|
||||
func (c *commander) Command(name string) (command func(map[string]interface{}) interface{}) {
|
||||
command, _ = c.commands[name]
|
||||
return
|
||||
// Command returns the command interface when passed a valid command name
|
||||
func (c *commander) Command(name string) func(map[string]interface{}) interface{} {
|
||||
return c.commands[name]
|
||||
}
|
||||
|
||||
// Commands returns the entire map of valid commands
|
||||
|
@ -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
146
doc.go
@ -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"
|
||||
|
@ -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...
|
||||
|
@ -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"),
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
func TestAnalogActuatorDriver(t *testing.T) {
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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...)
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
func TestTemperatureSensorDriver(t *testing.T) {
|
||||
|
@ -328,6 +328,9 @@ func (d *MFRC522Common) writeFifo(fifoData []byte) error {
|
||||
|
||||
func (d *MFRC522Common) readFifo(backData []byte) (uint8, error) {
|
||||
n, err := d.readByteData(regFIFOLevel) // Number of bytes in the FIFO
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if n > uint8(len(backData)) {
|
||||
return 0, fmt.Errorf("more data in FIFO (%d) than expected (%d)", n, len(backData))
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package mfrc522
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
type busConnMock struct {
|
||||
|
@ -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...
|
||||
|
@ -3,7 +3,7 @@ package gpio
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// Commands of the driver
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
@ -35,7 +35,7 @@ func TestButtonDriver(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestButtonDriverStart(t *testing.T) {
|
||||
sem := make(chan bool, 0)
|
||||
sem := make(chan bool)
|
||||
a := newGpioTestAdaptor()
|
||||
d := NewButtonDriver(a, "1")
|
||||
|
||||
@ -107,7 +107,7 @@ func TestButtonDriverStart(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestButtonDriverDefaultState(t *testing.T) {
|
||||
sem := make(chan bool, 0)
|
||||
sem := make(chan bool)
|
||||
a := newGpioTestAdaptor()
|
||||
d := NewButtonDriver(a, "1")
|
||||
d.DefaultState = 1
|
||||
|
@ -3,7 +3,7 @@ package gpio
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// Some useful divider
|
||||
|
@ -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)
|
||||
|
@ -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"),
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// EasyDriver object
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// Commands for the driver
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package gpio
|
||||
|
||||
import (
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// Access and command constants for the driver
|
||||
|
@ -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)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package gpio
|
||||
|
||||
import (
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// MotorDriver Represents a Motor
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
//
|
||||
|
@ -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)
|
||||
@ -35,7 +35,7 @@ func TestPIRMotionDriver(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPIRMotionDriverStart(t *testing.T) {
|
||||
sem := make(chan bool, 0)
|
||||
sem := make(chan bool)
|
||||
a := newGpioTestAdaptor()
|
||||
d := NewPIRMotionDriver(a, "1")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 }
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
@ -65,7 +66,7 @@ func (s *ServoDriver) Halt() (err error) { return }
|
||||
|
||||
// Move sets the servo to the specified angle. Acceptable angles are 0-180
|
||||
func (s *ServoDriver) Move(angle uint8) (err error) {
|
||||
if !(angle >= 0 && angle <= 180) {
|
||||
if angle > 180 {
|
||||
return ErrServoOutOfRange
|
||||
}
|
||||
s.CurrentAngle = angle
|
||||
|
@ -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)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
type phase [][4]byte
|
||||
@ -111,7 +111,7 @@ func (s *StepperDriver) Start() (err error) { return }
|
||||
// Run continuously runs the stepper
|
||||
func (s *StepperDriver) Run() (err error) {
|
||||
//halt if already moving
|
||||
if s.moving == true {
|
||||
if s.moving {
|
||||
s.Halt()
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ func (s *StepperDriver) Run() (err error) {
|
||||
|
||||
go func() {
|
||||
for {
|
||||
if s.moving == false {
|
||||
if !s.moving {
|
||||
break
|
||||
}
|
||||
s.step()
|
||||
@ -191,7 +191,7 @@ func (s *StepperDriver) Move(stepsToMove int) error {
|
||||
return s.Halt()
|
||||
}
|
||||
|
||||
if s.moving == true {
|
||||
if s.moving {
|
||||
//stop previous motion
|
||||
s.Halt()
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -58,7 +58,7 @@ func TestStepperDriverDefaultDirection(t *testing.T) {
|
||||
func TestStepperDriverInvalidDirection(t *testing.T) {
|
||||
d := initStepperMotorDriver()
|
||||
err := d.SetDirection("reverse")
|
||||
gobottest.Assert(t, err.(error), errors.New("Invalid direction. Value should be forward or backward"))
|
||||
gobottest.Assert(t, err, errors.New("Invalid direction. Value should be forward or backward"))
|
||||
}
|
||||
|
||||
func TestStepperDriverMoveForward(t *testing.T) {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
// Colors of the display
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -348,16 +348,12 @@ func (d *ADS1x15Driver) AnalogRead(pin string) (value int, err error) {
|
||||
switch pin {
|
||||
case "0-1":
|
||||
channel = 0
|
||||
break
|
||||
case "0-3":
|
||||
channel = 1
|
||||
break
|
||||
case "1-3":
|
||||
channel = 2
|
||||
break
|
||||
case "2-3":
|
||||
channel = 3
|
||||
break
|
||||
default:
|
||||
// read the voltage at a specific pin, compared to the ground
|
||||
channel, err = strconv.Atoi(pin)
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
func initTestADS1015DriverWithStubbedAdaptor() (*ADS1x15Driver, *i2cTestAdaptor) {
|
||||
@ -103,7 +103,7 @@ func TestADS1015AnalogRead(t *testing.T) {
|
||||
gobottest.Assert(t, val, 32767)
|
||||
gobottest.Assert(t, err, nil)
|
||||
|
||||
val, err = d.AnalogRead("3-2")
|
||||
_, err = d.AnalogRead("3-2")
|
||||
gobottest.Refute(t, err.Error(), nil)
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
func initTestADS1115DriverWithStubbedAdaptor() (*ADS1x15Driver, *i2cTestAdaptor) {
|
||||
@ -103,7 +103,7 @@ func TestADS1115AnalogRead(t *testing.T) {
|
||||
gobottest.Assert(t, val, 32767)
|
||||
gobottest.Assert(t, err, nil)
|
||||
|
||||
val, err = d.AnalogRead("3-2")
|
||||
_, err = d.AnalogRead("3-2")
|
||||
gobottest.Refute(t, err.Error(), nil)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -96,9 +96,9 @@ func TestADS1x15CommandsAnalogRead(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestADS1x15_ads1x15BestGainForVoltage(t *testing.T) {
|
||||
g, err := ads1x15BestGainForVoltage(1.5)
|
||||
g, _ := ads1x15BestGainForVoltage(1.5)
|
||||
gobottest.Assert(t, g, 2)
|
||||
|
||||
g, err = ads1x15BestGainForVoltage(20.0)
|
||||
_, err := ads1x15BestGainForVoltage(20.0)
|
||||
gobottest.Assert(t, err, errors.New("The maximum voltage which can be read is 6.144000"))
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -124,7 +124,7 @@ func TestBlinkMFirmwareVersion(t *testing.T) {
|
||||
return 0, errors.New("write error")
|
||||
}
|
||||
|
||||
version, err := d.FirmwareVersion()
|
||||
_, err := d.FirmwareVersion()
|
||||
gobottest.Assert(t, err, errors.New("write error"))
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ func TestBlinkMColor(t *testing.T) {
|
||||
return 0, errors.New("write error")
|
||||
}
|
||||
|
||||
color, err := d.Color()
|
||||
_, err := d.Color()
|
||||
gobottest.Assert(t, err, errors.New("write error"))
|
||||
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -12,10 +12,10 @@ type CCS811DriveMode uint8
|
||||
// Operating modes which dictate how often measurements are being made. If 0x00 is used as an operating mode, measurements will be disabled
|
||||
const (
|
||||
CCS811DriveModeIdle CCS811DriveMode = 0x00
|
||||
CCS811DriveMode1Sec = 0x01
|
||||
CCS811DriveMode10Sec = 0x02
|
||||
CCS811DriveMode60Sec = 0x03
|
||||
CCS811DriveMode250MS = 0x04
|
||||
CCS811DriveMode1Sec CCS811DriveMode = 0x01
|
||||
CCS811DriveMode10Sec CCS811DriveMode = 0x02
|
||||
CCS811DriveMode60Sec CCS811DriveMode = 0x03
|
||||
CCS811DriveMode250MS CCS811DriveMode = 0x04
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -6,13 +6,13 @@ type DRV2605Mode uint8
|
||||
// Operating modes, for use in SetMode()
|
||||
const (
|
||||
DRV2605ModeIntTrig DRV2605Mode = 0x00
|
||||
DRV2605ModeExtTrigEdge = 0x01
|
||||
DRV2605ModeExtTrigLvl = 0x02
|
||||
DRV2605ModePWMAnalog = 0x03
|
||||
DRV2605ModeAudioVibe = 0x04
|
||||
DRV2605ModeRealtime = 0x05
|
||||
DRV2605ModeDiagnose = 0x06
|
||||
DRV2605ModeAutocal = 0x07
|
||||
DRV2605ModeExtTrigEdge DRV2605Mode = 0x01
|
||||
DRV2605ModeExtTrigLvl DRV2605Mode = 0x02
|
||||
DRV2605ModePWMAnalog DRV2605Mode = 0x03
|
||||
DRV2605ModeAudioVibe DRV2605Mode = 0x04
|
||||
DRV2605ModeRealtime DRV2605Mode = 0x05
|
||||
DRV2605ModeDiagnose DRV2605Mode = 0x06
|
||||
DRV2605ModeAutocal DRV2605Mode = 0x07
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -267,7 +267,7 @@ func (d *GrovePiDriver) SetPinMode(pin byte, mode string) error {
|
||||
func getPin(pin string) string {
|
||||
if len(pin) > 1 {
|
||||
if strings.ToUpper(pin[0:1]) == "A" || strings.ToUpper(pin[0:1]) == "D" {
|
||||
return pin[1:len(pin)]
|
||||
return pin[1:]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)"),
|
||||
},
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -3,7 +3,7 @@ package i2c
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
"gobot.io/x/gobot/v2/gobottest"
|
||||
)
|
||||
|
||||
func TestNewConfig(t *testing.T) {
|
||||
|
@ -3,7 +3,7 @@ package i2c
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -30,7 +30,7 @@ type bitState uint8
|
||||
|
||||
const (
|
||||
clear bitState = 0x00
|
||||
set = 0x01
|
||||
set bitState = 0x01
|
||||
)
|
||||
|
||||
// Connection is a connection to an I2C device with a specified address
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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"),
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user