Skip to content

Commit

Permalink
Merge branch 'dev' into feature/jetson-nano-adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
dlstjq7685 authored Oct 20, 2022
2 parents 229a93e + 68a1b81 commit 8615079
Show file tree
Hide file tree
Showing 122 changed files with 12,031 additions and 4,474 deletions.
52 changes: 38 additions & 14 deletions .circleci/config.yml
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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ count.out
/stage
vendor/
.idea/
coverage.txt
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
1.16.0
---
* **bugfix**
* failing leftovers after usage of PR #569
* Fix servo and DC motors presence
* FIX the bug #568 without further impact, heavy improvements of tests
* fixed PinMode, SetPullUp and SetPolarity, unit tests activated
* ReadGPIO fixed with #576, failing leftovers for PinMode, SetPullUp and SetPolarity
* helper_test ReadByteData, ReadWordData to use reg
* **core**
* update uuid package and directly access it; remove archived uuid package
* **digispark**
* fix ReadByte & WriteByte, rework and add i2c tests
* remove useless code in i2c test
* **drivers**
* add AnalogActuatorDriver, analog temperature sensor, driver for PCF8591 (with 400kbit stabilization), driver for YL-40
* Adding support for hmc5883l compass
* bmp388 fix missing address write byte in test of Measurements
* drv2605l fix missing address write byte in test of Halt()
* introduce adafruit1109 2x16 LCD with 5 keys
* mcp23017: add mutex for write, hd44780: fix mutexes
* MCP3004: correct number of channels
* **raspi**
* fix raspi PWMPin.SetDutyCycle (#800)
* **tello**
* Guards Dji Tello Halt against nil dereference
* **test**
* don't panic on 'With*' allow simpler wrapping of drivers
* **tinkerboard**
* fix tinkerboard i2c0 to i2c4, improve comments in pin map, improve README

1.15.0
---
* **build**
Expand Down
64 changes: 45 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
.PHONY: test race cover robeaux examples test_with_coverage fmt_check
# include also examples in other than ./examples folder
ALL_EXAMPLES := $(shell grep -l -r --include "*.go" 'build example' ./)
# prevent examples with joystick (sdl2) and gocv (opencv) dependencies
EXAMPLES := $(shell grep -L 'joystick' $$(grep -L 'gocv' $(ALL_EXAMPLES)))

excluding_vendor := $(shell go list ./... | grep -v /vendor/)
.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check $(EXAMPLES)

# Run tests on all non-vendor directories
test:
go test -v $(excluding_vendor)
# opencv platform currently skipped to prevent install of preconditions
including_except := $(shell go list ./... | grep -v platforms/opencv)

# Run tests with race detection on all non-vendor directories
race:
go test -race $(excluding_vendor)
# Run tests on nearly all directories without test cache
test:
go test -count=1 -v $(including_except)

# Check for code well-formedness
fmt_check:
./ci/format.sh
# Run tests with race detection
test_race:
go test -race $(including_except)

# Test and generate coverage
test_with_coverage:
./ci/test.sh
# Test, generate and show coverage in browser
test_cover:
go test -v $(including_except) -coverprofile=coverage.txt ; \
go tool cover -html=coverage.txt ; \

robeaux:
ifeq (,$(shell which go-bindata))
Expand All @@ -36,9 +39,32 @@ endif
rm -rf node_modules/ ; \
go fmt ./robeaux/robeaux.go ; \

EXAMPLES := $(shell ls examples/*.go | sed -e 's/examples\///')
# Check for installed and module version match. Will exit with code 50 if not match.
# There is nothing bad in general, if you program with a higher version.
# At least the recipe "fmt_fix" will not work in that case.
version_check:
@gv=$$(echo $$(go version) | sed "s/^.* go\([0-9].[0-9]*\).*/\1/") ; \
mv=$$(grep -m 1 'go 1.' ./go.mod | sed "s/^go \([0-9].[0-9]*\).*/\1/") ; \
echo "go: $${gv}.*, go.mod: $${mv}" ; \
if [ "$${gv}" != "$${mv}" ]; then exit 50; fi ; \

# Check for bad code style and other issues
fmt_check:
gofmt -l ./
go vet ./...

examples:
for example in $(EXAMPLES) ; do \
go build -o /tmp/$$example examples/$$example ; \
done ; \
# Fix bad code style (will only be executed, on version match)
fmt_fix: version_check
go fmt ./...

examples: $(EXAMPLES)

examples_check:
$(MAKE) CHECK=ON examples

$(EXAMPLES):
ifeq ($(CHECK),ON)
go vet ./$@
else
go build -o /tmp/gobot_examples/$@ ./$@
endif
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Support for devices that use Inter-Integrated Circuit (I2C) have a shared set of
drivers provided using the `gobot/drivers/i2c` package:

- [I2C](https://en.wikipedia.org/wiki/I%C2%B2C) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/i2c)
- Adafruit 2x16 RGB-LCD with 5 keys
- Adafruit Motor Hat
- ADS1015 Analog to Digital Converter
- ADS1115 Analog to Digital Converter
Expand All @@ -271,25 +272,29 @@ drivers provided using the `gobot/drivers/i2c` package:
- BMP280 Barometric Pressure/Temperature/Altitude Sensor
- BMP388 Barometric Pressure/Temperature/Altitude Sensor
- DRV2605L Haptic Controller
- Generic driver for read and write values to/from register address
- Grove Digital Accelerometer
- GrovePi Expansion Board
- Grove RGB LCD
- HMC6352 Compass
- HMC8553L 3-Axis Digital Compass
- HMC5883L 3-Axis Digital Compass
- INA3221 Voltage Monitor
- JHD1313M1 LCD Display w/RGB Backlight
- L3GD20H 3-Axis Gyroscope
- LIDAR-Lite
- MCP23017 Port Expander
- MMA7660 3-Axis Accelerometer
- MPL115A2 Barometer
- MPL115A2 Barometric Pressure/Temperature
- MPU6050 Accelerometer/Gyroscope
- PCA9501 8-bit I/O port with interrupt, 2-kbit EEPROM
- PCA9685 16-channel 12-bit PWM/Servo Driver
- PCF8591 8-bit 4xA/D & 1xD/A converter
- SHT2x Temperature/Humidity
- SHT3x-D Temperature/Humidity
- SSD1306 OLED Display Controller
- TSL2561 Digital Luminosity/Lux/Light Sensor
- Wii Nunchuck Controller
- YL-40 Brightness/Temperature sensor, Potentiometer, analog input, analog output Driver

Support for devices that use Serial Peripheral Interface (SPI) have
a shared set of drivers provided using the `gobot/drivers/spi` package:
Expand Down
16 changes: 5 additions & 11 deletions appveyor.yml
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/...
2 changes: 2 additions & 0 deletions drivers/aio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ go get -d -u gobot.io/x/gobot/...
## 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)

More drivers are coming soon...
12 changes: 10 additions & 2 deletions drivers/aio/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ const (
Error = "error"
// Data event
Data = "data"
// Value event
Value = "value"
// Vibration event
Vibration = "vibration"
)

// AnalogReader interface represents an Adaptor which has Analog capabilities
// AnalogReader interface represents an Adaptor which has AnalogRead capabilities
type AnalogReader interface {
//gobot.Adaptor
AnalogRead(string) (val int, err error)
AnalogRead(pin string) (val int, err error)
}

// AnalogWriter interface represents an Adaptor which has AnalogWrite capabilities
type AnalogWriter interface {
//gobot.Adaptor
AnalogWrite(pin string, val int) (err error)
}
111 changes: 111 additions & 0 deletions drivers/aio/analog_actuator_driver.go
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)
}
}
Loading

0 comments on commit 8615079

Please sign in to comment.