Skip to content

Commit

Permalink
Merge pull request hybridgroup#64 from hybridgroup/pebble
Browse files Browse the repository at this point in the history
Pebble Support
  • Loading branch information
zankich committed Jun 10, 2014
2 parents 5e61ab6 + 3d454a7 commit 90423bc
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 0 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
32 changes: 32 additions & 0 deletions examples/pebble.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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() {
pebbleDriver.SendNotification("Hello Pebble!")
gobot.On(pebbleDriver.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.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work)

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()
}
91 changes: 91 additions & 0 deletions platforms/pebble/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Gobot for pebble

Gobot (http://gobot.io/) is a library for robotics and physical computing using Go

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 "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
https://github.com/hybridgroup/gobot

[![Build Status](https://secure.travis-ci.org/hybridgroup/gobot-pebble.png?branch=master)](http://travis-ci.org/hybridgroup/gobot-pebble)

## Installing

* 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 "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 publish command is PublishEventC and
message command is PendingMessageC

```
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() {
pebbleDriver.SendNotification("Hello Pebble!")
gobot.On(pebbleDriver.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.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work)
master.Robots = append(master.Robots, robot)
master.Start()
}
```

## Supported Features

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

## Documentation

We're busy adding documentation to our web site at http://gobot.io/ please check there as we continue to work on Gobot

Thank you!

## Contributing

* All patches must be provided under the Apache 2.0 License
* Please use the -s option in git to "sign off" that the commit is your work and you are providing it under the Apache 2.0 License
* Submit a Github Pull Request to the appropriate branch and ideally discuss the changes with us in IRC.
* We will look at the patch, test it out, and give you feedback.
* Avoid doing minor whitespace changes, renamings, etc. along with merged content. These will be done by the maintainers from time to time but they can complicate merges and should be done seperately.
* Take care to maintain the existing coding style.
* Add unit tests for any new or changed functionality
* All pull requests should be "fast forward"
* If there are commits after yours use “git rebase -i <new_head_branch>”
* If you have local changes you may need to use “git stash”
* For git help see [progit](http://git-scm.com/book) which is an awesome (and free) book on git

## License

Copyright (c) 2013-2014 The Hybrid Group. Licensed under the Apache 2.0 license.
15 changes: 15 additions & 0 deletions platforms/pebble/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pebble

func (sd *PebbleDriver) PublishEventC(params map[string]interface{}) {
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
}
34 changes: 34 additions & 0 deletions platforms/pebble/docs/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Functions

## PublishEvent(name string, data string)

It publishes an event.

#### Params

- **name** - **string** - event name
- **data** - **string** - value

#### 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**
13 changes: 13 additions & 0 deletions platforms/pebble/docs/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Events

## button

Sent when a pebble button is pressed.

## accel

Pebble watch acceleromenter data.

## tap

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

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

"testing"
)

func TestGobotPebble(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Gobot-Pebble Suite")
}
33 changes: 33 additions & 0 deletions platforms/pebble/pebble_adaptor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pebble

import (
"github.com/hybridgroup/gobot"
)

type PebbleAdaptor struct {
gobot.Adaptor
}

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

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

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

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

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

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

var _ = Describe("PebbleAdaptor", func() {
var (
adaptor *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))
})
})
57 changes: 57 additions & 0 deletions platforms/pebble/pebble_driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package pebble

import (
"github.com/hybridgroup/gobot"
)

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

type PebbleInterface interface {
}

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 (d *PebbleDriver) Start() bool { return true }

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

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

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

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

return m
}
40 changes: 40 additions & 0 deletions platforms/pebble/pebble_driver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package pebble

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

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

BeforeEach(func() {
adaptor = NewPebbleAdaptor("pebble")
driver = NewPebbleDriver(adaptor, "pebble")
})

It("Must be able to Start", func() {
Expect(driver.Start()).To(Equal(true))
})

It("Must be able to Halt", func() {
Expect(driver.Halt()).To(Equal(true))
})

It("Adds message when sending notification", func() {
driver.SendNotification("Hello")
Expect(driver.Messages[0]).To(Equal("Hello"))
})

It("Retrieves pending messages", func() {
driver.SendNotification("Hello")
driver.SendNotification("World")

Expect(driver.PendingMessage()).To(Equal("Hello"))
Expect(driver.PendingMessage()).To(Equal("World"))
Expect(driver.PendingMessage()).To(Equal(""))
})
})

0 comments on commit 90423bc

Please sign in to comment.