mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-11 19:29:20 +08:00
Merge branch 'dev'
This commit is contained in:
commit
a2c730ecc3
4
Makefile
4
Makefile
@ -1,7 +1,9 @@
|
||||
PACKAGES := "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/api" "github.com/hybridgroup/gobot/platforms/ardrone" "github.com/hybridgroup/gobot/platforms/beaglebone" "github.com/hybridgroup/gobot/platforms/digispark" "github.com/hybridgroup/gobot/platforms/firmata" "github.com/hybridgroup/gobot/platforms/gpio" "github.com/hybridgroup/gobot/platforms/i2c" "github.com/hybridgroup/gobot/platforms/leap" "github.com/hybridgroup/gobot/platforms/neurosky" "github.com/hybridgroup/gobot/platforms/pebble" "github.com/hybridgroup/gobot/platforms/spark" "github.com/hybridgroup/gobot/platforms/sphero" "github.com/hybridgroup/gobot/platforms/opencv" "github.com/hybridgroup/gobot/platforms/joystick"
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
for package in $(PACKAGES) ; do \
|
||||
go test $$package ; \
|
||||
done ; \
|
||||
|
||||
cover:
|
||||
echo "mode: count" > profile.cov ; \
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/firmata"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -15,10 +14,9 @@ func main() {
|
||||
led := gpio.NewLedDriver(firmataAdaptor, "led", "3")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(100*time.Millisecond, func() {
|
||||
val := sensor.Read()
|
||||
brightness := uint8(gobot.ToScale(gobot.FromScale(float64(val), 0, 1024), 0, 255))
|
||||
fmt.Println("sensor", val)
|
||||
gobot.On(sensor.Events["data"], func(data interface{}) {
|
||||
brightness := uint8(gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255))
|
||||
fmt.Println("sensor", data)
|
||||
fmt.Println("brightness", brightness)
|
||||
led.Brightness(brightness)
|
||||
})
|
||||
|
@ -249,12 +249,12 @@ func (b *board) process(data []byte) {
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
switch messageType {
|
||||
case ReportVersion:
|
||||
switch {
|
||||
case ReportVersion == messageType:
|
||||
b.MajorVersion, _ = buf.ReadByte()
|
||||
b.MinorVersion, _ = buf.ReadByte()
|
||||
b.Events = append(b.Events, event{Name: "report_version"})
|
||||
case AnalogMessage:
|
||||
case AnalogMessageRangeStart <= messageType && AnalogMessageRangeEnd >= messageType:
|
||||
leastSignificantByte, _ := buf.ReadByte()
|
||||
mostSignificantByte, _ := buf.ReadByte()
|
||||
|
||||
@ -264,7 +264,7 @@ func (b *board) process(data []byte) {
|
||||
b.Pins[b.AnalogPins[pin]].Value = int(value)
|
||||
b.Events = append(b.Events, event{Name: fmt.Sprintf("analog_read_%v", pin), Data: []byte{byte(value >> 24), byte(value >> 16), byte(value >> 8), byte(value & 0xff)}})
|
||||
|
||||
case DigitalMessage:
|
||||
case DigitalMessageRangeStart <= messageType && DigitalMessageRangeEnd >= messageType:
|
||||
port := messageType & 0x0F
|
||||
firstBitmask, _ := buf.ReadByte()
|
||||
secondBitmask, _ := buf.ReadByte()
|
||||
@ -279,7 +279,7 @@ func (b *board) process(data []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
case StartSysex:
|
||||
case StartSysex == messageType:
|
||||
currentBuffer := []byte{messageType}
|
||||
for {
|
||||
b, err := buf.ReadByte()
|
||||
|
@ -11,8 +11,11 @@ type AnalogSensorDriver struct {
|
||||
func NewAnalogSensorDriver(a AnalogReader, name string, pin string) *AnalogSensorDriver {
|
||||
d := &AnalogSensorDriver{
|
||||
Driver: gobot.Driver{
|
||||
Name: name,
|
||||
Pin: pin,
|
||||
Name: name,
|
||||
Pin: pin,
|
||||
Events: map[string]*gobot.Event{
|
||||
"data": gobot.NewEvent(),
|
||||
},
|
||||
Commands: make(map[string]func(map[string]interface{}) interface{}),
|
||||
Adaptor: a.(gobot.AdaptorInterface),
|
||||
},
|
||||
@ -27,9 +30,19 @@ func (a *AnalogSensorDriver) adaptor() AnalogReader {
|
||||
return a.Driver.Adaptor.(AnalogReader)
|
||||
}
|
||||
|
||||
func (a *AnalogSensorDriver) Start() bool { return true }
|
||||
func (a *AnalogSensorDriver) Init() bool { return true }
|
||||
func (a *AnalogSensorDriver) Halt() bool { return true }
|
||||
func (a *AnalogSensorDriver) Start() bool {
|
||||
value := 0
|
||||
gobot.Every(a.Interval, func() {
|
||||
newValue := a.Read()
|
||||
if newValue != value && newValue != -1 {
|
||||
value = newValue
|
||||
gobot.Publish(a.Events["data"], value)
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
func (a *AnalogSensorDriver) Init() bool { return true }
|
||||
func (a *AnalogSensorDriver) Halt() bool { return true }
|
||||
|
||||
func (a *AnalogSensorDriver) Read() int {
|
||||
return a.adaptor().AnalogRead(a.Pin)
|
||||
|
7
version.go
Normal file
7
version.go
Normal file
@ -0,0 +1,7 @@
|
||||
package gobot
|
||||
|
||||
const version = "0.5.1"
|
||||
|
||||
func Version() string {
|
||||
return version
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user