forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feature/jetson-nano-adaptor
- Loading branch information
Showing
122 changed files
with
12,031 additions
and
4,474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,49 @@ | ||
# Since switch to cimg, the GOPATH has been changed from /go to $HOME/go. | ||
# The latter will expand to the full path of /home/circleci/go. | ||
# On first run, this change may affect caching and some other commands if | ||
# you don’t correct the page in your config. | ||
# | ||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/circleci-images | ||
# - image: cimg/postgres:14.5.0 | ||
# | ||
# For more information, please read https://github.com/CircleCI-Public/cimg-go/blob/main/README.md | ||
|
||
version: 2 | ||
jobs: | ||
build: | ||
"test_core_and_drivers_with_coverage": | ||
docker: | ||
# specify the version | ||
- image: circleci/golang:1.15 | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/postgres:9.4 | ||
|
||
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} | ||
- image: cimg/go:1.17 | ||
steps: | ||
- checkout | ||
- run: | ||
name: Core and drivers tests | ||
command: go test -v -cpu=2 -coverprofile=coverage.txt -covermode=atomic . ./drivers/... | ||
name: Debug version | ||
command: go version | ||
- run: | ||
name: Firmata tests | ||
command: go test -v -cpu=2 ./platforms/firmata/... | ||
name: Core and drivers tests | ||
command: go test -v -coverprofile=coverage.txt -covermode=atomic . ./drivers/... | ||
- run: | ||
name: Code coverage | ||
command: | | ||
bash <(curl -s https://codecov.io/bash) | ||
"test_platforms": | ||
docker: | ||
- image: cimg/go:1.17 | ||
steps: | ||
- checkout | ||
- run: | ||
name: Debug version | ||
command: go version | ||
- run: | ||
# digispark needs libusb, joystick needs sdl2, opencv needs opencv | ||
name: Platform tests (except digispark, joystick, opencv) | ||
command: go test -v $(go list ./platforms/... | grep -v platforms/digispark | grep -v platforms/joystick | grep -v platforms/opencv) | ||
|
||
workflows: | ||
version: 2 | ||
build: | ||
jobs: | ||
- "test_core_and_drivers_with_coverage" | ||
- "test_platforms" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ count.out | |
/stage | ||
vendor/ | ||
.idea/ | ||
coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
version: "{build}" | ||
|
||
clone_folder: c:\gopath\src\gobot.io\x\gobot | ||
image: Visual Studio 2019 | ||
|
||
platform: | ||
- MinGW_x64 | ||
clone_folder: c:\gopath\src\gobot.io\x\gobot | ||
|
||
environment: | ||
PATH: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%PATH% | ||
GOPATH: c:\gopath | ||
GOROOT: c:\go | ||
GOVERSION: 1.15 | ||
TEST_EXTERNAL: 1 | ||
|
||
install: | ||
- set PATH=%PATH%;C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin | ||
- echo %PATH% | ||
- echo %GOPATH% | ||
before_test: | ||
- go version | ||
- go env | ||
- go get -d ./... | ||
|
||
build_script: | ||
- go test -v -cpu=2 . | ||
- go test -v -cpu=2 ./drivers/... | ||
- go test -v -cpu=2 ./platforms/firmata/... | ||
- go test -v -cpu=2 ./platforms/ble/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package aio | ||
|
||
import ( | ||
"strconv" | ||
|
||
"gobot.io/x/gobot" | ||
) | ||
|
||
// AnalogActuatorDriver represents an analog actuator | ||
type AnalogActuatorDriver struct { | ||
name string | ||
pin string | ||
connection AnalogWriter | ||
gobot.Eventer | ||
gobot.Commander | ||
scale func(input float64) (value int) | ||
lastValue float64 | ||
lastRawValue int | ||
} | ||
|
||
// NewAnalogActuatorDriver returns a new AnalogActuatorDriver given by an AnalogWriter and pin. | ||
// The driver supports customizable scaling from given float64 value to written int. | ||
// 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 | ||
func NewAnalogActuatorDriver(a AnalogWriter, pin string) *AnalogActuatorDriver { | ||
d := &AnalogActuatorDriver{ | ||
name: gobot.DefaultName("AnalogActuator"), | ||
connection: a, | ||
pin: pin, | ||
Commander: gobot.NewCommander(), | ||
scale: func(input float64) (value int) { return int(input) }, | ||
} | ||
|
||
d.AddCommand("Write", func(params map[string]interface{}) interface{} { | ||
val, err := strconv.ParseFloat(params["val"].(string), 64) | ||
if err != nil { | ||
return err | ||
} | ||
return d.Write(val) | ||
}) | ||
|
||
d.AddCommand("RawWrite", func(params map[string]interface{}) interface{} { | ||
val, _ := strconv.Atoi(params["val"].(string)) | ||
return d.RawWrite(val) | ||
}) | ||
|
||
return d | ||
} | ||
|
||
// Start starts driver | ||
func (a *AnalogActuatorDriver) Start() (err error) { return } | ||
|
||
// Halt is for halt | ||
func (a *AnalogActuatorDriver) Halt() (err error) { return } | ||
|
||
// Name returns the drivers name | ||
func (a *AnalogActuatorDriver) Name() string { return a.name } | ||
|
||
// SetName sets the drivers name | ||
func (a *AnalogActuatorDriver) SetName(n string) { a.name = n } | ||
|
||
// Pin returns the drivers pin | ||
func (a *AnalogActuatorDriver) Pin() string { return a.pin } | ||
|
||
// Connection returns the drivers Connection | ||
func (a *AnalogActuatorDriver) Connection() gobot.Connection { return a.connection.(gobot.Connection) } | ||
|
||
// RawWrite write the given raw value to the actuator | ||
func (a *AnalogActuatorDriver) RawWrite(val int) (err error) { | ||
a.lastRawValue = val | ||
return a.connection.AnalogWrite(a.Pin(), val) | ||
} | ||
|
||
// SetScaler substitute the default 1:1 return value function by a new scaling function | ||
func (a *AnalogActuatorDriver) SetScaler(scaler func(float64) int) { | ||
a.scale = scaler | ||
} | ||
|
||
// Write writes the given value to the actuator | ||
func (a *AnalogActuatorDriver) Write(val float64) (err error) { | ||
a.lastValue = val | ||
rawValue := a.scale(val) | ||
return a.RawWrite(rawValue) | ||
} | ||
|
||
// RawValue returns the last written raw value | ||
func (a *AnalogActuatorDriver) RawValue() (val int) { | ||
return a.lastRawValue | ||
} | ||
|
||
// Value returns the last written value | ||
func (a *AnalogActuatorDriver) Value() (val float64) { | ||
return a.lastValue | ||
} | ||
|
||
func AnalogActuatorLinearScaler(fromMin, fromMax float64, toMin, toMax int) func(input float64) (value int) { | ||
m := float64(toMax-toMin) / (fromMax - fromMin) | ||
n := float64(toMin) - m*fromMin | ||
return func(input float64) (value int) { | ||
if input <= fromMin { | ||
return toMin | ||
} | ||
if input >= fromMax { | ||
return toMax | ||
} | ||
return int(input*m + n) | ||
} | ||
} |
Oops, something went wrong.