Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
Reformat source using gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
deadprogram committed Nov 14, 2013
1 parent bd87131 commit 7a1e5c4
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 147 deletions.
38 changes: 19 additions & 19 deletions adaptor.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package gobot

type Adaptor struct {
Name string
Port string
Connected bool
Params map[string]string
Name string
Port string
Connected bool
Params map[string]string
}

func (Adaptor) NewAdaptor(a Adaptor) Adaptor {
return a
return a
}

func (a *Adaptor) Finalize() bool{
if a.IsConnected() {
a.Disconnect()
}
return true
func (a *Adaptor) Finalize() bool {
if a.IsConnected() {
a.Disconnect()
}
return true
}

func (a *Adaptor) Connect() bool {
a.Connected = true
return true
a.Connected = true
return true
}

func (a *Adaptor) Disconnect() bool {
a.Connected = false
return true
a.Connected = false
return true
}

func (a *Adaptor) Reconnect() bool {
if !a.IsConnected(){
return a.Connect()
}
return true
if !a.IsConnected() {
return a.Connect()
}
return true
}

func (a *Adaptor) IsConnected() bool {
return a.Connected
return a.Connected
}
37 changes: 18 additions & 19 deletions connection.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
package gobot

import (
"fmt"
"reflect"
"fmt"
"reflect"
)

type Connection struct {
Name string
Adaptor interface{}
Port string
Robot *Robot
Params map[string]string

Name string
Adaptor interface{}
Port string
Robot *Robot
Params map[string]string
}

func NewConnection(a interface{}, r *Robot) *Connection {
c := new(Connection)
c.Name = reflect.ValueOf(a).Elem().FieldByName("Name").String()
c.Port = reflect.ValueOf(a).Elem().FieldByName("Port").String()
c.Robot = r
c.Adaptor = a
return c
c := new(Connection)
c.Name = reflect.ValueOf(a).Elem().FieldByName("Name").String()
c.Port = reflect.ValueOf(a).Elem().FieldByName("Port").String()
c.Robot = r
c.Adaptor = a
return c
}

func (c *Connection) Connect() {
fmt.Println("Connecting to " + c.Name + " on port " + c.Port + "...")
reflect.ValueOf(c.Adaptor).MethodByName("Connect").Call([]reflect.Value{})
fmt.Println("Connecting to " + c.Name + " on port " + c.Port + "...")
reflect.ValueOf(c.Adaptor).MethodByName("Connect").Call([]reflect.Value{})
}

func (c *Connection) Disconnect() {
reflect.ValueOf(c.Adaptor).MethodByName("Disconnect").Call([]reflect.Value{})
reflect.ValueOf(c.Adaptor).MethodByName("Disconnect").Call([]reflect.Value{})
}

func (c *Connection) IsConnected() bool {
return reflect.ValueOf(c.Adaptor).MethodByName("IsConnected").Call([]reflect.Value{})[0].Bool()
return reflect.ValueOf(c.Adaptor).MethodByName("IsConnected").Call([]reflect.Value{})[0].Bool()
}

func (c *Connection) AdaptorName() string {
return c.Name
return c.Name
}
36 changes: 18 additions & 18 deletions device.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package gobot

import (
"fmt"
"reflect"
"fmt"
"reflect"
)

type Device struct {
Name string
Interval string
Robot *Robot
Driver interface{}
Params map[string]string
Name string
Interval string
Robot *Robot
Driver interface{}
Params map[string]string
}

func NewDevice(driver interface{}, r *Robot) *Device {
d := new(Device)
d.Name = reflect.ValueOf(driver).Elem().FieldByName("Name").String()
d.Robot = r
d.Driver = driver
return d
d := new(Device)
d.Name = reflect.ValueOf(driver).Elem().FieldByName("Name").String()
d.Robot = r
d.Driver = driver
return d
}

func (d *Device) Start() {
fmt.Println("Device " + d.Name + " started")
r := reflect.ValueOf(d.Driver).MethodByName("StartDriver")
if r.IsValid() {
r.Call([]reflect.Value{})
}
fmt.Println("Device " + d.Name + " started")
r := reflect.ValueOf(d.Driver).MethodByName("StartDriver")
if r.IsValid() {
r.Call([]reflect.Value{})
}
}

func (d *Device) Command(method_name string, arguments []string) {
//dt.Driver.Command(method_name, arguments)
//dt.Driver.Command(method_name, arguments)
}
14 changes: 7 additions & 7 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package gobot
import "fmt"

type Driver struct {
Interval string
Pin string
Name string
Params map[string]string
Events map[string]chan interface{}
Interval string
Pin string
Name string
Params map[string]string
Events map[string]chan interface{}
}

func NewDriver(d Driver) Driver {
return d
return d
}

func (d *Driver) Start() {
fmt.Println("Starting driver " + d.Name + "...")
fmt.Println("Starting driver " + d.Name + "...")
}
76 changes: 39 additions & 37 deletions gobot.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
package gobot

import (
"time"
"math/rand"
"net"
"math/rand"
"net"
"time"
)

func Every(t string, f func()) {
dur := parseDuration(t)
go func(){
for{
time.Sleep(dur)
go f()
}
}()
dur := parseDuration(t)
go func() {
for {
time.Sleep(dur)
go f()
}
}()
}

func After(t string, f func()) {
dur := parseDuration(t)
go func(){
time.Sleep(dur)
f()
}()
dur := parseDuration(t)
go func() {
time.Sleep(dur)
f()
}()
}

func parseDuration(t string) time.Duration {
return ParseDuration(t)
return ParseDuration(t)
}
func ParseDuration(t string) time.Duration {
dur, err := time.ParseDuration(t)
if err != nil {
panic(err)
}
return dur
dur, err := time.ParseDuration(t)
if err != nil {
panic(err)
}
return dur
}

func Random(min int, max int) int {
rand.Seed(time.Now().UTC().UnixNano())
return rand.Intn(max - min) + min
rand.Seed(time.Now().UTC().UnixNano())
return rand.Intn(max-min) + min
}

func On(cs chan interface{}) interface{}{
for s := range cs {
return s
}
return nil
func On(cs chan interface{}) interface{} {
for s := range cs {
return s
}
return nil
}

func Work(robots []Robot) {
for s := range robots {
go robots[s].Start()
}
for{time.Sleep(10 * time.Millisecond)}
for s := range robots {
go robots[s].Start()
}
for {
time.Sleep(10 * time.Millisecond)
}
}

func ConnectTo(port string) net.Conn {
tcpPort, err := net.Dial("tcp", port)
if err != nil {
panic(err)
}
return tcpPort
tcpPort, err := net.Dial("tcp", port)
if err != nil {
panic(err)
}
return tcpPort
}
8 changes: 4 additions & 4 deletions port.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package gobot

type Port struct {
Name string
Name string
}

func (Port) NewPort(p string) *Port{
return new(Port)
func (Port) NewPort(p string) *Port {
return new(Port)
}

func (p *Port) ToString() string {
return p.Name
return p.Name
}
Loading

0 comments on commit 7a1e5c4

Please sign in to comment.