diff --git a/platforms/keyboard/README.md b/platforms/keyboard/README.md index 896467ad..b79e5874 100644 --- a/platforms/keyboard/README.md +++ b/platforms/keyboard/README.md @@ -25,7 +25,7 @@ import ( func main() { gbot := gobot.NewGobot() - keys := keyboard.NewKeyboardDriver("keyboard") + keys := keyboard.NewDriver("keyboard") work := func() { gobot.On(keys.Event("key"), func(data interface{}) { diff --git a/platforms/keyboard/doc.go b/platforms/keyboard/doc.go index 5ea93ad0..3c4591aa 100644 --- a/platforms/keyboard/doc.go +++ b/platforms/keyboard/doc.go @@ -21,7 +21,7 @@ Example: func main() { gbot := gobot.NewGobot() - keys := keyboard.NewKeyboardDriver("keyboard") + keys := keyboard.NewDriver() work := func() { gobot.On(keys.Event("key"), func(data interface{}) { diff --git a/platforms/keyboard/keyboard_driver.go b/platforms/keyboard/keyboard_driver.go index e21a975d..86d686e3 100644 --- a/platforms/keyboard/keyboard_driver.go +++ b/platforms/keyboard/keyboard_driver.go @@ -12,18 +12,17 @@ const ( Key = "key" ) -type KeyboardDriver struct { +type Driver struct { name string - connect func(*KeyboardDriver) (err error) - listen func(*KeyboardDriver) + connect func(*Driver) (err error) + listen func(*Driver) stdin *os.File gobot.Eventer } -func NewKeyboardDriver(name string) *KeyboardDriver { - k := &KeyboardDriver{ - name: name, - connect: func(k *KeyboardDriver) (err error) { +func NewDriver() *Driver { + k := &Driver{ + connect: func(k *Driver) (err error) { if err := configure(); err != nil { return err } @@ -31,7 +30,7 @@ func NewKeyboardDriver(name string) *KeyboardDriver { k.stdin = os.Stdin return }, - listen: func(k *KeyboardDriver) { + listen: func(k *Driver) { ctrlc := bytes{3} for { @@ -60,12 +59,13 @@ func NewKeyboardDriver(name string) *KeyboardDriver { return k } -func (k *KeyboardDriver) Name() string { return k.name } -func (k *KeyboardDriver) Connection() gobot.Connection { return nil } +func (k *Driver) Name() string { return k.name } +func (k *Driver) SetName(n string) { k.name = n } +func (k *Driver) Connection() gobot.Connection { return nil } // Start initializes keyboard by grabbing key events as they come in and // publishing a key event -func (k *KeyboardDriver) Start() (errs []error) { +func (k *Driver) Start() (errs []error) { if err := k.connect(k); err != nil { return []error{err} } @@ -76,7 +76,7 @@ func (k *KeyboardDriver) Start() (errs []error) { } // Halt stops camera driver -func (k *KeyboardDriver) Halt() (errs []error) { +func (k *Driver) Halt() (errs []error) { if originalState != "" { return restore() } diff --git a/platforms/keyboard/keyboard_driver_test.go b/platforms/keyboard/keyboard_driver_test.go index 7da37669..a2e6070b 100644 --- a/platforms/keyboard/keyboard_driver_test.go +++ b/platforms/keyboard/keyboard_driver_test.go @@ -8,21 +8,20 @@ import ( "github.com/hybridgroup/gobot/gobottest" ) -var _ gobot.Driver = (*KeyboardDriver)(nil) +var _ gobot.Driver = (*Driver)(nil) -func initTestKeyboardDriver() *KeyboardDriver { - d := NewKeyboardDriver("keyboard") - d.connect = func(k *KeyboardDriver) (err error) { +func initTestKeyboardDriver() *Driver { + d := NewDriver() + d.connect = func(k *Driver) (err error) { k.stdin = &os.File{} return nil } - d.listen = func(k *KeyboardDriver) {} + d.listen = func(k *Driver) {} return d } func TestKeyboardDriver(t *testing.T) { d := initTestKeyboardDriver() - gobottest.Assert(t, d.Name(), "keyboard") gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil)) }