Skip to content

Commit

Permalink
Fix default Interval initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jun 6, 2014
1 parent 6f14570 commit 57bb8bb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
26 changes: 23 additions & 3 deletions device.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
type Device interface {
Start() bool
Halt() bool
setInterval(time.Duration)
getInterval() time.Duration
setName(string)
getName() string
}

type JsonDevice struct {
Expand Down Expand Up @@ -54,15 +58,31 @@ func NewDevice(driver DriverInterface, r *Robot) *device {
d := new(device)
s := reflect.ValueOf(driver).Type().String()
d.Type = s[1:len(s)]
d.Name = FieldByNamePtr(driver, "Name").String()
d.Name = driver.getName()
d.Robot = r
if FieldByNamePtr(driver, "Interval").String() == "" {
FieldByNamePtr(driver, "Interval").SetString("0.1s")
if driver.getInterval() == 0 {
driver.setInterval(10 * time.Millisecond)
}
d.Driver = driver
return d
}

func (d *device) setInterval(t time.Duration) {
d.Interval = t
}

func (d *device) getInterval() time.Duration {
return d.Interval
}

func (d *device) setName(s string) {
d.Name = s
}

func (d *device) getName() string {
return d.Name
}

func (d *device) Start() bool {
log.Println("Device " + d.Name + " started")
return d.Driver.Start()
Expand Down
20 changes: 20 additions & 0 deletions driver.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,24 @@ type Driver struct {
type DriverInterface interface {
Start() bool
Halt() bool
setInterval(time.Duration)
getInterval() time.Duration
setName(string)
getName() string
}

func (d *Driver) setInterval(t time.Duration) {
d.Interval = t
}

func (d *Driver) getInterval() time.Duration {
return d.Interval
}

func (d *Driver) setName(s string) {
d.Name = s
}

func (d *Driver) getName() string {
return d.Name
}
Empty file modified test_helper.go
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gobot

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

var _ = Describe("Utils", func() {
Expand Down

0 comments on commit 57bb8bb

Please sign in to comment.