From 57bb8bbce6c38834761ec78984e265281bb9c37e Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Fri, 6 Jun 2014 14:44:16 -0700 Subject: [PATCH] Fix default Interval initialization --- device.go | 26 +++++++++++++++++++++++--- driver.go | 20 ++++++++++++++++++++ test_helper.go | 0 utils_test.go | 2 +- 4 files changed, 44 insertions(+), 4 deletions(-) mode change 100644 => 100755 device.go mode change 100644 => 100755 driver.go mode change 100644 => 100755 test_helper.go diff --git a/device.go b/device.go old mode 100644 new mode 100755 index 53125341d..af78fe0a1 --- a/device.go +++ b/device.go @@ -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 { @@ -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() diff --git a/driver.go b/driver.go old mode 100644 new mode 100755 index 38cc5f152..252019b72 --- a/driver.go +++ b/driver.go @@ -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 } diff --git a/test_helper.go b/test_helper.go old mode 100644 new mode 100755 diff --git a/utils_test.go b/utils_test.go index 9f55f70bf..95d9b5fba 100644 --- a/utils_test.go +++ b/utils_test.go @@ -1,9 +1,9 @@ package gobot import ( - "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "time" ) var _ = Describe("Utils", func() {