Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jun 29, 2014
2 parents d941a39 + 34ccc13 commit a2c730e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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 ; \
Expand Down
8 changes: 3 additions & 5 deletions examples/firmata_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

func main() {
Expand All @@ -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)
})
Expand Down
10 changes: 5 additions & 5 deletions platforms/firmata/firmata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand All @@ -279,7 +279,7 @@ func (b *board) process(data []byte) {
}
}

case StartSysex:
case StartSysex == messageType:
currentBuffer := []byte{messageType}
for {
b, err := buf.ReadByte()
Expand Down
23 changes: 18 additions & 5 deletions platforms/gpio/analog_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gobot

const version = "0.5.1"

func Version() string {
return version
}

0 comments on commit a2c730e

Please sign in to comment.