Skip to content

Commit

Permalink
Updating pebble with new structure
Browse files Browse the repository at this point in the history
Movinf events creation to newPebbleDriver method

Adding basic button support

Ignoring sass-cache and robeaux

Adding accelerometer example

Adding tap support

Use custom server instead of classic martini

This is to disable logs and avoid noise

Adding correct format to code

Adding notification support to pebble driver

Adding tests and correcting PendingMessage

Updating documentation

Format to example accel

Removing logging changes in api

Removing temp fix in api, will be attended later

Removing extra space
  • Loading branch information
Javier Cervantes authored and Javier Cervantes committed Jun 10, 2014
1 parent 3de9d86 commit 3d454a7
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.sass-cache
*.test
robeaux
44 changes: 20 additions & 24 deletions examples/pebble.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
package main

import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/pebble"
"fmt"
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/pebble"
)

func main() {
pebbleAdaptor := new(gobotPebble.PebbleAdaptor)
pebbleAdaptor.Name = "Pebble"
master := gobot.NewGobot()
api.NewApi(master).Start()

pebble := gobotPebble.NewPebble(pebbleAdaptor)
pebble.Name = "pebble"
pebbleAdaptor := pebble.NewPebbleAdaptor("pebble")
pebbleDriver := pebble.NewPebbleDriver(pebbleAdaptor, "pebble")

master := gobot.GobotMaster()
api := gobot.Api(master)
api.Port = "8080"
work := func() {
pebbleDriver.SendNotification("Hello Pebble!")
gobot.On(pebbleDriver.Events["button"], func(data interface{}) {
fmt.Println("Button pushed: " + data.(string))
})

work := func() {
gobot.On(pebble.Events["button"], func(data interface{}) {
fmt.Println("Button pushed: " + data.(string))
})
}
gobot.On(pebbleDriver.Events["tap"], func(data interface{}) {
fmt.Println("Tap event detected")
})
}

robot := gobot.Robot{
Connections: []gobot.Connection{pebbleAdaptor},
Devices: []gobot.Device{pebble},
Work: work,
}
robot := gobot.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work)

robot.Name = "pebble"

master.Robots = append(master.Robots, &robot)
master.Start()
master.Robots = append(master.Robots, robot)
master.Start()
}
27 changes: 27 additions & 0 deletions examples/pebble_accelerometer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/pebble"
)

func main() {
master := gobot.NewGobot()
api.NewApi(master).Start()

pebbleAdaptor := pebble.NewPebbleAdaptor("pebble")
pebbleDriver := pebble.NewPebbleDriver(pebbleAdaptor, "pebble")

work := func() {
gobot.On(pebbleDriver.Events["accel"], func(data interface{}) {
fmt.Println(data.(string))
})
}

robot := gobot.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work)

master.Robots = append(master.Robots, robot)
master.Start()
}
48 changes: 40 additions & 8 deletions platforms/pebble/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Gobot (http://gobot.io/) is a library for robotics and physical computing using
This repository contains the Gobot adaptor for Pebble smart watch (http://getpebble.com/).

It uses the Pebble 2.0 SDK, and requires the 2.0 iOS or Android app,
and that the "Chomps" app (https://github.com/hybridgroup/chomps)
and that the "watchbot" app (https://github.com/hybridgroup/watchbot)
has been installed on the Pebble watch.

For more information about Gobot, check out the github repo at
Expand All @@ -17,21 +17,53 @@ https://github.com/hybridgroup/gobot

* Install running: ```go get github.com/hybridgroup/gobot-pebble``
* Install Pebble 2.0 iOS or Android app. (If you haven't already)
* Follow README to install and configure "Chomps" on your watch: https://github.com/hybridgroup/chomps
* Follow README to install and configure "watchbot" on your watch: https://github.com/hybridgroup/watchbot

## Using

* Before running the example, make sure configuration settings match with your program,
in example, api host is your computer IP, robot name is 'pebble', robot api port is 8080 and command is PublishEventC
in example, api host is your computer IP, robot name is 'pebble', robot api port is 8080 and publish command is PublishEventC and
message command is PendingMessageC

your example code here...
## Supported Features
```
package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/pebble"
)
func main() {
master := gobot.NewGobot()
api.NewApi(master).Start()
pebbleAdaptor := pebble.NewPebbleAdaptor("pebble")
pebbleDriver := pebble.NewPebbleDriver(pebbleAdaptor, "pebble")
* We support event detection of 3 main pebble buttons.
work := func() {
pebbleDriver.SendNotification("Hello Pebble!")
gobot.On(pebbleDriver.Events["button"], func(data interface{}) {
fmt.Println("Button pushed: " + data.(string))
})
## Upcoming Features
gobot.On(pebbleDriver.Events["tap"], func(data interface{}) {
fmt.Println("Tap event detected")
})
}
robot := gobot.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work)
master.Robots = append(master.Robots, robot)
master.Start()
}
```

## Supported Features

* Accelerometer support
* We support event detection of 3 main pebble buttons.
* Accelerometer events
* Pushing data to pebble watch

## Documentation
Expand Down
12 changes: 11 additions & 1 deletion platforms/pebble/commands.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package pebble

func (sd *PebbleDriver) PublishEventC(params map[string]interface{}) {
sd.PublishEvent(params["name"].(string), params["data"].(string))
sd.PublishEvent(params["name"].(string), params["data"].(string))
}

func (sd *PebbleDriver) SendNotificationC(params map[string]interface{}) {
sd.SendNotification(params["message"].(string))
}

func (sd *PebbleDriver) PendingMessageC(params map[string]interface{}) interface{} {
m := make(map[string]string)
m["result"] = sd.PendingMessage()
return m
}
20 changes: 20 additions & 0 deletions platforms/pebble/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,23 @@ It publishes an event.
#### API Command

**PublishEventC**

## PendingMessage()

It returns messages to be sent as notifications to pebble (Not recommended to be used directly)

#### API Command

**PendingMessageC**

## SendNotification(message string)

Sends notification to watch.

#### Params

- **message** - **string** - notification text

#### API Command

**SendNotification**
8 changes: 8 additions & 0 deletions platforms/pebble/docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
## button

Sent when a pebble button is pressed.

## accel

Pebble watch acceleromenter data.

## tap

When a pebble watch tap event is detected.
10 changes: 5 additions & 5 deletions platforms/pebble/gobot-pebble_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package pebble

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
"testing"
)

func TestGobotPebble(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Gobot-Pebble Suite")
RegisterFailHandler(Fail)
RunSpecs(t, "Gobot-Pebble Suite")
}
Binary file removed platforms/pebble/pebble.test
Binary file not shown.
24 changes: 16 additions & 8 deletions platforms/pebble/pebble_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ type PebbleAdaptor struct {
gobot.Adaptor
}

func (me *PebbleAdaptor) Connect() bool {
return true
func NewPebbleAdaptor(name string) *PebbleAdaptor {
return &PebbleAdaptor{
Adaptor: gobot.Adaptor{
Name: name,
},
}
}

func (me *PebbleAdaptor) Reconnect() bool {
return true
func (a *PebbleAdaptor) Connect() bool {
return true
}

func (me *PebbleAdaptor) Disconnect() bool {
return true
func (a *PebbleAdaptor) Reconnect() bool {
return true
}

func (me *PebbleAdaptor) Finalize() bool {
return true
func (a *PebbleAdaptor) Disconnect() bool {
return true
}

func (a *PebbleAdaptor) Finalize() bool {
return true
}
40 changes: 20 additions & 20 deletions platforms/pebble/pebble_adaptor_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package pebble

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("PebbleAdaptor", func() {
var (
adaptor *PebbleAdaptor
)
var (
adaptor *PebbleAdaptor
)

BeforeEach(func() {
adaptor = new(PebbleAdaptor)
})
BeforeEach(func() {
adaptor = NewPebbleAdaptor("pebble")
})

It("Must be able to Finalize", func() {
Expect(adaptor.Finalize()).To(Equal(true))
})
It("Must be able to Connect", func() {
Expect(adaptor.Connect()).To(Equal(true))
})
It("Must be able to Disconnect", func() {
Expect(adaptor.Disconnect()).To(Equal(true))
})
It("Must be able to Reconnect", func() {
Expect(adaptor.Reconnect()).To(Equal(true))
})
It("Must be able to Finalize", func() {
Expect(adaptor.Finalize()).To(Equal(true))
})
It("Must be able to Connect", func() {
Expect(adaptor.Connect()).To(Equal(true))
})
It("Must be able to Disconnect", func() {
Expect(adaptor.Disconnect()).To(Equal(true))
})
It("Must be able to Reconnect", func() {
Expect(adaptor.Reconnect()).To(Equal(true))
})
})
52 changes: 36 additions & 16 deletions platforms/pebble/pebble_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,52 @@ import (

type PebbleDriver struct {
gobot.Driver
Adaptor *PebbleAdaptor
Messages []string
Adaptor *PebbleAdaptor
}

type PebbleInterface interface {
}

func NewPebble(adaptor *PebbleAdaptor) *PebbleDriver {
d := new(PebbleDriver)
d.Events = make(map[string]chan interface{})
d.Adaptor = adaptor
d.Commands = []string{
"PublishEventC",
}
return d
func NewPebbleDriver(adaptor *PebbleAdaptor, name string) *PebbleDriver {
return &PebbleDriver{
Driver: gobot.Driver{
Name: name,
Events: map[string]chan interface{}{
"button": make(chan interface{}),
"accel": make(chan interface{}),
"tap": make(chan interface{}),
},
Commands: []string{
"PublishEventC",
"SendNotificationC",
"PendingMessageC",
},
},
Messages: []string{},
Adaptor: adaptor,
}
}

func (me *PebbleDriver) Init() bool {
me.Events["button"] = make(chan interface{})
func (d *PebbleDriver) Start() bool { return true }

return true
func (d *PebbleDriver) Halt() bool { return true }

func (d *PebbleDriver) PublishEvent(name string, data string) {
gobot.Publish(d.Events[name], data)
}

func (me *PebbleDriver) Start() bool { return true }
func (d *PebbleDriver) SendNotification(message string) string {
d.Messages = append(d.Messages, message)
return message
}

func (me *PebbleDriver) Halt() bool { return true }
func (d *PebbleDriver) PendingMessage() string {
if len(d.Messages) < 1 {
return ""
}
m := d.Messages[0]
d.Messages = d.Messages[1:]

func (sd *PebbleDriver) PublishEvent(name string, data string) {
gobot.Publish(sd.Events[name], data)
return m
}
Loading

0 comments on commit 3d454a7

Please sign in to comment.